Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmod-saintmode: Allow using blacklist in vcl_backend_error #216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ VMOD_TESTS = \
tests/saintmode/test03.vtc \
tests/saintmode/test04.vtc \
tests/saintmode/test05.vtc \
tests/saintmode/test06.vtc \
tests/saintmode/test07.vtc \
tests/str/test01.vtc \
tests/str/test02.vtc \
tests/str/test03.vtc \
Expand Down
28 changes: 28 additions & 0 deletions src/tests/saintmode/test07.vtc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
varnishtest "Test saintmode blacklist in vcl_backend_error"

varnish v1 -vcl+backend {
import saintmode from "${vmod_builddir}/.libs/libvmod_saintmode.so";

backend ko {
.host = "192.0.2.1";
.port = "80";
}

sub vcl_init {
new sm = saintmode.saintmode(ko, 1);
}

sub vcl_backend_fetch {
set bereq.backend = sm.backend();
}

sub vcl_backend_error {
saintmode.blacklist(0.5s);
}
} -start

client c1 {
txreq -url "/foo"
rxresp
expect resp.status == 503
} -run
4 changes: 2 additions & 2 deletions src/vmod_saintmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ vmod_denylist(VRT_CTX, struct vmod_priv *priv, VCL_DURATION expires) {
}

CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (ctx->method != VCL_MET_BACKEND_RESPONSE) {
if (!ctx->bo || !ctx->bo->director_resp) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, we can get rid of this, and just use $Restrict in the VCC.
@delthas, do you want to do it, or should I?

VSLb(ctx->vsl, SLT_VCL_Error, "saintmode.denylist() called"
" outside of vcl_backend_response");
" outside of vcl_backend_response and vcl_backend_error");
return;
}

Expand Down
5 changes: 3 additions & 2 deletions src/vmod_saintmode.vcc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ Example::
$ABI vrt
$Function VOID denylist(PRIV_VCL, DURATION expires)

Marks the backend as sick for a specific object. Used in vcl_backend_response.
Marks the backend as sick for a specific object. Used in vcl_backend_response
and vcl_backend_error.
Corresponds to the use of ``beresp.saintmode`` in Varnish 3.0. Only available
in vcl_backend_response.
in vcl_backend_response and vcl_backend_error.

Example::

Expand Down