Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2599

Undertow dispatch unlocked too soon due to receiveFullBytes callback on I/O thread

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 2.3.18.Final
    • Core
    • None
    • Hide

      Send payload larger than 256 KB (e.g. including {"whatever": "X".repeat(256 * 1024))}. In k8s, 256Kb is more then enough for stable reproduce. 

      !For localhost payload should be much bigger and still might not reproduce constantly.

      Show
      Send payload larger than 256 KB (e.g. including { "whatever": "X".repeat(256 * 1024) )}. In k8s, 256Kb is more then enough for stable reproduce.  !For localhost payload should be much bigger and still might not reproduce constantly.

      Under certain conditions - for example, with a large payload or when buffer reuse is forced by client behavior - HttpServerExchange.getRequestReceiver().receiveFullBytes(...) performs the actual async buffer read and, importantly, invokes the read-body callback on the I/O thread which prematurely unlocks the dispatch(...), so the handler returns before the request is fully processed.

      public void handle(HttpServerExchange exchange) throws Exception {
          exchange.dispatch(() -> {
              // ...
              exchange.getRequestReceiver().receiveFullBytes((ex, messageBytes) -> {
                  // ...async work here, which needs to
                  // be dispatched again since execution
                  // might be in the I/O thread.
                  // This is not obvious, because it's
                  // not documented and not consistently reproducible.
              });
          });
      } 

      I’ve put it as Minor, since I’m not sure whether this is a bug or undocumented behavior – but it was painful to figure out, so at the very least it would be better if this was clearly documented.

              flaviarnn Flavia Rainone
              dkhudin Dmytro Khudin
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: