Skip to content

fix: avoid KeepAlive NPE when idle fires before WS handshake#30

Open
typefield wants to merge 2 commits into
open-dingtalk:mainfrom
typefield:fix/keepalive-npe-idle-before-handshake
Open

fix: avoid KeepAlive NPE when idle fires before WS handshake#30
typefield wants to merge 2 commits into
open-dingtalk:mainfrom
typefield:fix/keepalive-npe-idle-before-handshake

Conversation

@typefield

Copy link
Copy Markdown

Summary

Fix intermittent [DingTalk] connection operation failed caused by NullPointerException in KeepAliveHandler.userEventTriggered when IdleStateEvent arrives before WebSocket handshake completes.

Related customer ticket: Aone 84622857 (appKey dingthkn4if9cbyfskxi, stack points to KeepAliveHandler.java:56).

Root cause

  • WebsocketIdleHandler starts idle timers after TCP connect
  • KeepAliveHandler.channel is only assigned on HANDSHAKE_COMPLETE
  • Idle event before handshake → channel.eventLoop() NPE
  • NettyClientHandler.exceptionCaught only logged and did not close, so pool retry made it look like “retry recovers”

Changes

  • Only schedule ping after handshake (active == true)
  • Prefer live Channel reference; null/inactive safe
  • Clear active/channel on channelInactive
  • Close channel in exceptionCaught to trigger reconnect
  • Unit tests for idle-before/after handshake

Test plan

  • mvn -pl app-stream-network/app-stream-network-ws -am test -Dtest=KeepAliveHandlerTest
  • Customer upgrades to this build and confirms no intermittent connection operation failed NPE

Made with Cursor

玉澜 and others added 2 commits July 23, 2026 15:35
IdleStateHandler can emit IdleStateEvent after TCP connect but before
WebSocket handshake completes. KeepAliveHandler previously dereferenced
a null channel field, logging "connection operation failed" and leaving
half-dead connections that recovered only after pool retry.

Also close the channel in exceptionCaught so the session pool reconnects
promptly. Fixes customer intermittent Stream disconnect (Aone 84622857).

Co-authored-by: Cursor <cursoragent@cursor.com>
Strengthen regression for Aone 84622857 KeepAlive NPE and ensure
NettyClientHandler closes channel on connection failures.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant