New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #4383 - avoid NPE from MultiPart Cleanup #4388
Conversation
Always assign _parts when constructed so it is never null. Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine.
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
a15e661
to
979f88f
Compare
This will stop two threads from parsing at the same time. Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java
Show resolved
Hide resolved
jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java
Show resolved
Hide resolved
jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per offline discussion, lets remove the synchronization and just ensure that creation and cleaning of parts is sane.
jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Outdated
Show resolved
Hide resolved
- Removed synchronization for parsing by two threads. - Introduced an atomic state to decide when it is safe to remove the parts. The call to deleteParts will now cancel the parsing and only delete the parts when the parser exits. Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@janbartel I added an atomic state to decide when it is safe to remove the parts. When you call |
private volatile File _tmpDir; | ||
private volatile boolean _deleteOnExit; | ||
private volatile boolean _writeFilesWithFilenames; | ||
private volatile boolean _parsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need _parsed if you have the state variable.
public boolean isEmpty() | ||
{ | ||
if (_parts == null) | ||
if (!_parsed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment.
@@ -397,6 +407,31 @@ public boolean isEmpty() | |||
*/ | |||
public void deleteParts() | |||
{ | |||
while (true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really would prefer not to have these kind of loops.
continue; | ||
break; | ||
|
||
case ERROR: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe both ERROR and COMPLETED are both terminal states?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just moving to ERROR
state is not enough, the ERROR
state is indicating that the parsing thread should exit, and the move to COMPLETED
indicates that it has exited and will not create anymore parts.
@@ -431,15 +466,7 @@ public void deleteParts() | |||
if (!_parsed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment
@@ -588,6 +617,27 @@ else if (len == -1) | |||
if (parser != null) | |||
parser.parse(BufferUtil.EMPTY_BUFFER, true); | |||
} | |||
finally | |||
{ | |||
while (true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, would really prefer to avoid loops if possible.
…s called use synchronized state instead of atomic reference Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
@janbartel nudge |
@lachlan-roberts move these changes over to |
Always assign _parts when constructed so it is never null.
Signed-off-by: Lachlan Roberts lachlan@webtide.com
Closes #4383