Skip to content

fix: proxy filter panics did not run applyFiltersOnError#3969

Merged
szuecs merged 2 commits into
masterfrom
fix/filter-panic-did-not-run-response-filters-on-error
Apr 17, 2026
Merged

fix: proxy filter panics did not run applyFiltersOnError#3969
szuecs merged 2 commits into
masterfrom
fix/filter-panic-did-not-run-response-filters-on-error

Conversation

@szuecs
Copy link
Copy Markdown
Member

@szuecs szuecs commented Apr 16, 2026

fix #3966

Example: In the proxy a route with filter chain a() -> b() exists.

b() panics and a() implements errorHandlerFilter interface and return true from HandleErrorResponse(). In this case we should run the filter a().Response(), because we need to cleanup things as expected.

For example scheduler filters like fifo() or lifo() need to decrement the active concurrent requests counter or we will stop requests in the queue, wich would be miss leading. If we panic in b() and everyone will look at behavior of a(), because we are stuck there caused by not running the cleanup.

Example: In the proxy a route with filter chain a() -> b() exists.

b() panics and a() implements errorHandlerFilter interface and return
true from HandleErrorResponse().  In this case we should run the
filter a().Response(), because we need to cleanup things as expected.

For example scheduler filters like fifo() or lifo() need to decrement
the active concurrent requests counter or we will stop requests in the
queue, wich would be miss leading.  If we panic in b() and everyone will
look at behavior of a(), because we are stuck there caused by not
running the cleanup.

Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
@szuecs szuecs added the bugfix Bug fixes and patches label Apr 16, 2026
Copy link
Copy Markdown
Collaborator

@madumalt madumalt left a comment

Choose a reason for hiding this comment

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

some minor comments, suggestions to change some variable names. The logic seems sound to me!

Comment thread proxy/proxy_test.go
Comment thread proxy/proxy.go

// applies filters to a request
func (p *Proxy) applyFiltersToRequest(f []*routing.RouteFilter, ctx *context) []*routing.RouteFilter {
func (p *Proxy) applyFiltersToRequest(f []*routing.RouteFilter, ctx *context, counter *int) []*routing.RouteFilter {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shouldn't the var name be index instead of counter ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No because we count number of filters executed in the request path

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I approved the PR, if the suggestion doen't make sense, just ignore it :)

Comment thread proxy/proxy.go

func (p *Proxy) do(ctx *context, parentSpan ot.Span) (err error) {
var requestElapsed, responseElapsed time.Duration
processedFiltersCounter := 0
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

similar to the above comment, shouldn't this be something like lastProcessedFilterIndex ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, same here and "last" would be misleading

Comment thread proxy/proxy_test.go Outdated
Signed-off-by: Sandor Szücs <sandor.szuecs@zalando.de>
@szuecs
Copy link
Copy Markdown
Member Author

szuecs commented Apr 17, 2026

👍

Comment thread proxy/proxy.go
}

if processedFiltersCounter != 0 {
p.applyFiltersOnError(ctx, ctx.route.Filters[:processedFiltersCounter])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What if we have another panic in this call?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

then we likely panic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fixes and patches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

filters that were processed on request should be called in response if there was a filter panic

3 participants