Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] proxy AsyncMiddleManServlet: ProxyWriter onWritePossible never called

Hello again jetty-users,

I'm converting the bespoke proxy service I inherited to use jetty-proxy's provided AsyncMiddleManServlet
and am encountering an unfortunate hang that I'm not sure how to diagnose.

Here's the rough code I'm going on right now (very much a work in progress):
https://gist.github.com/stevenschlansker/0a1a8e2e6d773efd9a681ffb599eeb6d

I'm using jetty server and client 9.4.7

Here's most of the test run at DEBUG output for reference:
https://gist.githubusercontent.com/stevenschlansker/435d16686440071935eab4c72211d98a/raw/04831a7688ce09a7333d88d891cd0024036fcde0/gistfile1.txt

Essentially, I am firing a single test request at my subclass of AsyncMiddleManServlet
and attempting to read data through the proxy.

I can see the proxy request and response work fine, and then the servlet starts to asynchronously
copy data back from the proxy response to write out to the test case.  The ProxyResponseListener fires
and reads two chunks, the 17 bytes of the actual content and then the 0-byte "completed" chunk.

The WriteListener was not yet created, so #onContent goes on to set the Content-Length to -1 (Strange,
don't we already know the Content-Length is 17?) and then calls setWriteListener -- and nothing further
happens until timeouts start firing and the test fails.

I can confirm that the write listener is set via the
2017-10-02T14:51:35.911Z DEBUG <> [default-pool-46] o.e.jetty.server.HttpChannelState - onWritePossible HttpChannelState@153cd8eb{s=DISPATCHED a=STARTED i=true r=IDLE w=false}
line, however since s=DISPATCHED (not ASYNC_WAIT) there is no immediate wake at onWritePossible and nobody
ever seems to come back later to notify the proxy that it could write data out.

Shots in the dark:

* I've invalidated some assumption about the HttpServletResponse state with my processing code, that causes it not to already be in an ASYNC_WAIT state when Proxy writes start
* I've somehow prevented a necessary callback from getting invoked that would have later triggered an onWritePossible
* Somehow the Jetty container is failing to uphold the WriteListener contract of calling onWritePossible at least once after registering it (Implausible???)

I'll continue probing down; difficult since introducing breakpoints entirely changes the flow of the asynchronous code...
but in the meantime if anyone has any ideas of how I might narrow down the cause of this frustrating problem I'd be forever grateful :)

Thanks in advance!

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail


Back to the top