eclipse-ee4j / eclipse-ee4j/jersey
Missing First Byte in InputStream with PHP Client on Jetty Server 12 and Jersey
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
I noticed a problem with the first byte being missing in the inputStream when I call Jetty server 12 with Jersey as the servlet container. This only happens from PHP with a sufficiently large payload (my test is about 1.5MB). It doesn't happen when the same call is made in Java (but I can't replicate the identical behavior with Java).
It seems that the only Jersey versions exhibiting the issue are 3.1.8 and 3.1.9, not 4.0.0-M1 or < 3.1.7.
```
java --version
openjdk 17.0.12 2024-07-16
OpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu222.04, mixed mode, sharing)
12.0.14
PHP version 7.4.33
PHP version 8.3.12
```
Affected Jersey Versions:
```
3.1.8
3.1.9
```
In this repository:
https://github.com/Ostico/TestBug-Jersey-Container
there are two Main classes that are both Jetty servers. The first Main.java has a Jersey ServletContainer, while the second Main2.java is a pure implementation in Jetty12.
The first one exhibits the bug/problem, while the second does not.
What happens is that when running the PHP script PhpCurlCall.php (essentially a while loop with a POST call), the server at some point starts to return a 500 internal server error (my code raise an exception), indicating that the first byte is different from what was expected.
This happens randomly and sporadically.
```
/usr/bin/php /home/hashashiyyin/IdeaProjects/TestJetty12/PhpCurlCall.php
Response: {"status":"OK"}
Response: {"status":"OK"}
Response:
Error 500 Internal Server Error
HTTP ERROR 500 Internal Server Error
URI:http://localhost:8080/api/v1/analyze
STATUS:500
MESSAGE:Internal Server Error
Powered by Jetty:// 12.0.14
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response: {"status":"OK"}
Response:
Error 500 Internal Server Error
HTTP ERROR 500 Internal Server Error
URI:http://localhost:8080/api/v1/analyze
STATUS:500
MESSAGE:Internal Server Error
Powered by Jetty:// 12.0.14
Response: {"status":"OK"}
Response:
Error 500 Internal Server Error
HTTP ERROR 500 Internal Server Error
URI:http://localhost:8080/api/v1/analyze
STATUS:500
MESSAGE:Internal Server Error
Powered by Jetty:// 12.0.14
```
This is a TcpDump that allowed me to see that the issue could be related to the Expect: 100-continue header, which is not sent from the Java client.
```
$# sudo tcpdump -i lo -A -s 0 'tcp port 8080 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'
listening on lo, link-type EN10MB (Ethernet), snapshot length 262144 bytes
18:13:23.928242 IP localhost.46056 > localhost.http-alt: Flags [P.], seq 3037887848:3037888012, ack 2284102578, win 512, options [nop,nop,TS val 3435051440 ecr 3435051440], length 164: HTTP: POST /api/v1/analyze HTTP/1.1
E.....@.@..4..............}h.$.............
........POST /api/v1/analyze HTTP/1.1
Host: localhost:8080
Accept: */*
Content-Length: 1591670
Content-Type: application/x-www-form-urlencoded
Expect: 100-continue
18:13:23.929355 IP localhost.http-alt > localhost.46056: Flags [P.], seq 1:26, ack 164, win 512, options [nop,nop,TS val 3435051442 ecr 3435051440], length 25: HTTP: HTTP/1.1 100 Continue
E..M..@.@................$....~......A.....
........HTTP/1.1 100 Continue
18:13:23.929432 IP localhost.46056 > localhost.http-alt: Flags [.], seq 164:32932, ack 26, win 512, options [nop,nop,TS val 3435051442 ecr 3435051442], length 32768: HTTP
E..4..@.@.................~..$......~).....
........[{"_id":"6707ffeb262211f0a87ba1ac","index":0,"guid" ... ect... etc ...
```
Contributor guide
Assessment
This issue has not been assessed yet.