From 9b9cc15b055e3a6f2987f274bfd34dd4c030fc0f Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 24 Jan 2020 09:49:00 +1100 Subject: [PATCH] Issue 4383 - changes from review Signed-off-by: Lachlan Roberts --- .../server/MultiPartFormInputStream.java | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartFormInputStream.java b/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartFormInputStream.java index 5d8eaffaa4ac..bc7fe0445b45 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartFormInputStream.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/MultiPartFormInputStream.java @@ -56,10 +56,16 @@ *

* Deleting the parts can be done from a different thread if the parts are parsed asynchronously. * Because of this we use the state to fail the parsing and coordinate which thread will delete any remaining parts. - * The deletion of parts is done by the cleanup thread in all cases except the transition from ERROR->DELETED which + * The deletion of parts is done by the cleanup thread in all cases except the transition from DELETING->DELETED which * is done by the parsing thread. *

*
{@code
+ * UNPARSED - Parsing has not started, there are no parts which need to be cleaned up.
+ * PARSING  - The parsing thread is reading from the InputStream and generating parts.
+ * PARSED   - Parsing has complete and no more parts will be generated.
+ * DELETING - deleteParts() has been called while we were in PARSING state, parsing thread will do the delete.
+ * DELETED  - The parts have been deleted, this is the terminal state.
+ *
  *                              deleteParts()
  *     +--------------------------------------------------------------+
  *     |                                                              |
@@ -67,8 +73,8 @@
  *  UNPARSED -------> PARSING --------> PARSED  ------------------>DELETED
  *                      |                                             ^
  *                      |                                             |
- *                      +----------------> ERROR ---------------------+
- *                        deleteParts()             parsing thread
+ *                      +---------------> DELETING -------------------+
+ *                        deleteParts()               parsing thread
  * }
* @see https://tools.ietf.org/html/rfc7578 */ @@ -79,8 +85,8 @@ private enum State UNPARSED, PARSING, PARSED, - DELETED, - ERROR + DELETING, + DELETED } private static final Logger LOG = Log.getLogger(MultiPartFormInputStream.class); @@ -406,11 +412,11 @@ public void deleteParts() switch (state) { case DELETED: - case ERROR: + case DELETING: return; case PARSING: - state = State.ERROR; + state = State.DELETING; return; case UNPARSED: @@ -423,10 +429,10 @@ public void deleteParts() } } - uncheckedDeleteParts(); + delete(); } - private void uncheckedDeleteParts() + private void delete() { MultiException err = null; for (List parts : _parts.values()) @@ -631,7 +637,7 @@ else if (len == -1) state = State.PARSED; break; - case ERROR: + case DELETING: state = State.DELETED; cleanup = true; break; @@ -642,7 +648,7 @@ else if (len == -1) } if (cleanup) - uncheckedDeleteParts(); + delete(); } }