{"record":{"id":"0b2a5f84664802f0","repo":"TooTallNate/Java-WebSocket","slug":"1002-0b2a5f","errorCode":"1002","errorMessage":"Continuous frame sequence not completed.","messagePattern":"Continuous frame sequence not completed\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/java_websocket/drafts/Draft_6455.java","lineNumber":907,"sourceCode":"    }\n  }\n\n  @Override\n  public void processFrame(WebSocketImpl webSocketImpl, Framedata frame)\n      throws InvalidDataException {\n    Opcode curop = frame.getOpcode();\n    if (curop == Opcode.CLOSING) {\n      processFrameClosing(webSocketImpl, frame);\n    } else if (curop == Opcode.PING) {\n      webSocketImpl.getWebSocketListener().onWebsocketPing(webSocketImpl, frame);\n    } else if (curop == Opcode.PONG) {\n      webSocketImpl.updateLastPong();\n      webSocketImpl.getWebSocketListener().onWebsocketPong(webSocketImpl, frame);\n    } else if (!frame.isFin() || curop == Opcode.CONTINUOUS) {\n      processFrameContinuousAndNonFin(webSocketImpl, frame, curop);\n    } else if (currentContinuousFrame != null) {\n      log.error(\"Protocol error: Continuous frame sequence not completed.\");\n      throw new InvalidDataException(CloseFrame.PROTOCOL_ERROR,\n          \"Continuous frame sequence not completed.\");\n    } else if (curop == Opcode.TEXT) {\n      processFrameText(webSocketImpl, frame);\n    } else if (curop == Opcode.BINARY) {\n      processFrameBinary(webSocketImpl, frame);\n    } else {\n      log.error(\"non control or continious frame expected\");\n      throw new InvalidDataException(CloseFrame.PROTOCOL_ERROR,\n          \"non control or continious frame expected\");\n    }\n  }\n\n  /**\n   * Process the frame if it is a continuous frame or the fin bit is not set\n   *\n   * @param webSocketImpl the websocket implementation to use\n   * @param frame         the current frame\n   * @param curop         the current Opcode","sourceCodeStart":889,"sourceCodeEnd":925,"githubUrl":"https://github.com/TooTallNate/Java-WebSocket/blob/afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d/src/main/java/org/java_websocket/drafts/Draft_6455.java#L889-L925","documentation":"processFrame throws InvalidDataException with CloseFrame.PROTOCOL_ERROR (close code 1002) when a new data frame (non-FIN TEXT/BINARY or otherwise) arrives while a continuous (fragmented) frame sequence is still open. Per RFC 6455, while a fragmented message is in progress, only CONTINUATION frames may arrive.","triggerScenarios":"Receiving a TEXT or BINARY frame (with FIN or not) before the previous fragmented message was terminated by a FIN frame; processFrame's currentContinuousFrame != null branch fires.","commonSituations":"Buggy or malicious clients interleaving messages mid-fragmentation; proxies rewriting frames; app code that sends new messages from other threads while a fragmented send is in flight (sender-side violation reflected back on strict peers).","solutions":["Fix the peer/sender to complete each fragmented message with a FIN frame before starting a new one","If sending fragments yourself, serialize sends (single writer thread / queue) so fragments are never interleaved","Handle the 1002 close on the receiving side: catch InvalidDataException and log the offending peer","Verify intermediate proxies preserve frame boundaries and fragmentation"],"exampleFix":"// before: interleaved sends from two threads break fragmentation\nthreadA.sendFragmented(bigMessage);\nthreadB.send(\"quick msg\"); // protocol error on receiver\n// after\nsynchronized (sendLock) {\n  sendFragments(bigMessage); // completes with FIN\n  send(\"quick msg\");\n}","handlingStrategy":"validation","validationCode":"// before sending a new message, ensure no fragmented message is still open\nif (fragmentedSendInProgress.get()) {\n  throw new IllegalStateException(\"Cannot start a new message while a fragmented send is in progress\");\n}","typeGuard":null,"tryCatchPattern":"// in your WebSocketListener\n@Override\npublic void onWebsocketError(WebSocket conn, Exception ex) {\n  if (ex instanceof InvalidDataException\n      && ((InvalidDataException) ex).getCloseCode() == CloseFrame.PROTOCOL_ERROR) {\n    log.warn(\"Peer violated fragmentation rules; closing with 1002\");\n  }\n}","preventionTips":["Serialize all sends through a single writer/queue so fragments cannot interleave","Always terminate fragmented messages with a FIN frame before starting a new one","Only send CONTINUATION frames while a fragmented sequence is open"],"tags":["websocket","fragmentation","protocol-error","close-code-1002"],"backgroundTag":"invalid-state-transition","analyzedSha":"afeacbf8c0f6f6a761c9d9daed8c813dd3b8ed7d","analyzedAt":"2026-09-09T14:39:47.546Z","contentChangedAt":"2026-09-09T14:39:47.546Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}