RestController send response w/o closing channel if keep alive


(Simone Scarduzio) #1

Hello,
My plugin needs to return a 401 HTTP response code at times.

So what I do today is using the channel and send a response:
https://github.com/sscarduzio/elasticsearch-readonlyrest-plugin/blob/master/src/main/java/org/elasticsearch/plugin/readonlyrest/IndexLevelActionFilter.java#L156

So this is what makes the netty thread hang:

  1. Client sends a HTTP request with Connection:Keep-Alive
  2. I respond 401 (controller is closed, netty channel is not)
  3. Client continues in the same connection with a new request
  4. My plugin never get called again (because rest controller was closed, I guess)

See the snoop from Wireshark:

Digging on ES code, I noticed there's no keep alive check here when we close the controller,

https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/rest/RestController.java#L401

But you do correctly check if the header is set when you go about sending the response at the channel level

Is this a bug on your side or should I send a 401 response differently from my plugin?


(Jason Tedor) #2

No, that's not closing the controller (it's not closable) nor the connection, that's only closing the resource channel so the circuit breaker accounting is correct. The bug is on your side, keep alive works fine.


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.