[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] Possible race condition with ByteBuffers in HttpParser

Daniel,

what you describe does indeed sound incorrect. It sounds very much like a buffer has been returned to the buffer pool when it should not have been. We have occasionally had bugs like that, but I've not seen a report for one in 9.4.8.

We do have a classÂLeakTrackingByteBufferPool, which we can use to check that buffers are not being doubly allocated. Tell me a bit more about how you setup your server and I'll be able to inform you how to use that pool.... but still upgrade to 9.4.11

regards


On 20 June 2018 at 01:40, Daniel Potter <dpotte01@xxxxxxxx> wrote:

OS: weâre running in a dockerized Debian 9 distro, Linux 4.9.87-linuxkit-aufs.

Â

Weâre using jetty as âconfiguredâ by dropwizard. It uses com.codahale.metrics.jetty9.InstrumentedQueuedThreadPool, which looks like a thin subclass of org.eclipse.jetty.util.QueuedThreadPool to export metrics.

Â

Pretty much everything else is jettyâs defaults:

ByteBufferPool is org.eclipse.jetty.io.ArrayByteBufferPool

ServerConnector is org.eclipse.jetty.server.ServerConnector

SelectorManager is org.eclipse.jetty.io.SelectorManager

Cipher suite is not custom, using JVM default-provided one.

Â

Regards,

Daniel

Â

From: jetty-dev-bounces@xxxxxxxxxxx [mailto:jetty-dev-bounces@eclipse.org] On Behalf Of Joakim Erdfelt
Sent: Tuesday, June 19, 2018 17:00


To: Jetty @ Eclipse developer discussion list <jetty-dev@xxxxxxxxxxx>
Subject: Re: [jetty-dev] Possible race condition with ByteBuffers in HttpParser

Â

What other changes have you made to your infrastructure on Jetty?

Are you using a custom ThreadPool perhaps? (meaning not the recommended QueuedThreadPool)

Or have you provided your own ByteBufferPool?

Or using a custom ServerConnector?

Or custom SelectorManager?

Or a custom cipher suite? (bouncy castle?)

Or are you running on an older OS? (such as a Linux kernel 3.x based distribution? or a minimal alpine based distro?)

Or are you running on an OS with known NIO select bugs? (eg: Microsoft Windows?)

Â


Joakim Erdfelt / joakim@xxxxxxxxxxx

Â

On Tue, Jun 19, 2018 at 4:30 PM, Daniel Potter <dpotte01@xxxxxxxx> wrote:

Agreedâthatâs definitely the clientâs quirk. Still, it should be ignored and harmless when using HTTP/1.1 to spec, I believe?

Â

I confirmed the bug both with, and without, TLS.

Â

Â

From: jetty-dev-bounces@xxxxxxxxxxx [mailto:jetty-dev-bounces@eclipse.org] On Behalf Of Joakim Erdfelt
Sent: Tuesday, June 19, 2018 16:11


To: Jetty @ Eclipse developer discussion list <jetty-dev@xxxxxxxxxxx>
Subject: Re: [jetty-dev] Possible race condition with ByteBuffers in HttpParser

Â

Strange request ...

Â

GET /api/groups/id/c689acc7-ee13-3482-aa7b-c6a13419431c/items/name/G6-A7-Sample HTTP/1.1

...

Connection: keep-alive

Â

Your client specified "HTTP/1.1" and then used "Connection: keep-alive" (a HTTP/1.0 only feature/concept).

Â

Is this over SSL/TLS perhaps?

If so, does this issue manifest without SSL/TLS?

Â


Joakim Erdfelt / joakim@xxxxxxxxxxx

Â

On Tue, Jun 19, 2018 at 4:04 PM, Daniel Potter <dpotte01@xxxxxxxx> wrote:

Hi Joakim,

Â

Certainly, weâll upgrade to 9.4.11 ASAPâ but the issue is still present, unfortunately. Apologies for the outdated links, Iâve been chasing this bug for a while.

Â

I was suspicious of the client at first, too (jersey 2.26), but the request doesnât look wrong at all to me. Hereâs an example of the snippet extracted by Wireshark (Auth token change is my edit, but this should still give a more clear example)ârequest first, followed by the response from jetty:

Â

GET /api/groups/id/c689acc7-ee13-3482-aa7b-c6a13419431c/items/name/G6-A7-Sample HTTP/1.1

Authorization: Bearer tokenWhichIsBase64

debug-request-id: ITEM-8fe57f6fcc81573a

User-Agent: Jersey/2.26 (HttpUrlConnection 1.8.0_172)

Host: localhost:18443

Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

Connection: keep-alive

Â

HTTP/1.1 400 Unknown Version

Content-Type: text/html;charset=iso-8859-1

Content-Length: 58

Connection: close

Â

<h1>Bad Message 400</h1><pre>reason: Unknown Version</pre>

Â

Iâll upgrade my local build to 9.4.11 and will keep trying to provide an isolated repro case.

Â

Best,
Daniel

Â

From: jetty-dev-bounces@xxxxxxxxxxx [mailto:jetty-dev-bounces@eclipse.org] On Behalf Of Joakim Erdfelt
Sent: Tuesday, June 19, 2018 15:26
To: Jetty @ Eclipse developer discussion list <jetty-dev@xxxxxxxxxxx>
Subject: Re: [jetty-dev] Possible race condition with ByteBuffers in HttpParser

Â

Also, what kind of client are you using to test with?

The description smells of a protocol bug introduced by a client. (the "unknown version" portion tells us the parse was parsing a line that didn't have a HTTP version)

Â

If you have a setup that even occasionally produces this result we would like to see it.

Â


Joakim Erdfelt / joakim@xxxxxxxxxxx

Â

On Tue, Jun 19, 2018 at 2:51 PM, Daniel Potter <dpotte01@xxxxxxxx> wrote:

Hello jetty-dev,

Â

Iâve been debugging a rather strange, timing-sensitive bug in a project that showed up after upgrading jetty from 9.2.13 -> 9.4.8 (still repro on 9.4.11), and have stumbled upon some suspicious behavior within jettyâs request handling/HTTP parsing layers. I havenât been able to isolate a standalone repro case yet, but while I work on doing so, I was wondering if any of this sounded familiar or suspicious to anyone?

Â

Summary of conditions to repro:

  • High volume of GET requests (200-400 per second)
  • A fairly small payload per request (around 500 bytes including all HTTP headers)

Â

Observed repro:

  • Somewhat sporadically (usually between 5-10 minutes, although it can take up to 30), we see an HTTP 400 error returned to the client, due to âunknown versionâ (i.e., invalid HTTP version spec in the request). However, there is nothing unusual about the request that fails (compared to all the thousands that succeed). Iâve confirmed via Wireshark that the exact request in question is perfectly valid.

Â

  • With similar probability, we sometimes see a duplicated response from an earlier request sent as the response to the subsequent request (so far, always on the same connection, but we havenât ruled out that it might be happening across multiple connections). The end result is that all HTTP responses are shifted down by one, causing mayhem on the client side. According to Wireshark, the HTTP stream goes something like this:

    Request 1
    Response 1

    Request 2
    Response 2

    Request 3
    Response 2

    Request 4
    Response 3

    Request 5
    Response 4
    â

Â

Iâve narrowed the investigation down to what appears to be a race condition in filling on-heap buffers from an org.eclipse.jetty.io.ByteBufferPool with the HTTP request bytes, and parsing the request out of those same buffers. In particular, when the 400 âunknown versionâ error hits, org.eclipse.jetty.http.HttpParser.parseNext(buffer) is called with a buffer that appears to be in fill mode (position at end-of-content, limit at max capacity); yet by the time code has progressed to where the BAD_REQUEST_400 is thrown, the buffer has flipped back to flush mode (with position and limit both at the end-of-content). _methodString and _uri are both parsed to be gibberish (based on content that is read past the end of the bufferâs limit), and _version remains null.

Â

Can anyone help confirm that the ByteBuffer behavior inside of HttpParser is unexpected? And, if by chance, this looks like anything else you all may have encountered?

Â

Regards,
Daniel

Â

Daniel Potter // Senior Software Engineer
PROSÂ // Powering Modern Commerce with Dynamic Pricing Science

Â


_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-dev

Â


_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-dev

Â


_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-dev

Â


_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-dev



--
Greg Wilkins <gregw@xxxxxxxxxxx> CTO http://webtide.com