Skip to content

fix(qwp-ws): enforce per-call contract for flushAndGetSequence() and override drain() (#7142)#48

Open
adi1719 wants to merge 2 commits into
questdb:mainfrom
adi1719:ws-drain-method
Open

fix(qwp-ws): enforce per-call contract for flushAndGetSequence() and override drain() (#7142)#48
adi1719 wants to merge 2 commits into
questdb:mainfrom
adi1719:ws-drain-method

Conversation

@adi1719

@adi1719 adi1719 commented Jun 14, 2026

Copy link
Copy Markdown

QwpWebSocketSender.flushAndGetSequence() documented a per-call contract
(return -1 when nothing published by this call) but returned the global
published-FSN watermark instead. An empty flush after a previous publish
would return the previous FSN rather than -1.

This change enforces the formal per-call contract by comparing the
published FSN before and after the flush work — returning the new FSN
only when this call actually advanced it, and -1 otherwise.

Because the default Sender.drain() implementation relies on
flushAndGetSequence() to obtain its wait target, an empty-flush
returning -1 would cause drain() to short-circuit immediately even
with prior unacknowledged frames in flight. To preserve correct drain
semantics, QwpWebSocketSender now overrides drain() to use the
current published-FSN watermark as the wait target (matching the
existing drainOnClose() approach).

Changes:

  • QwpWebSocketSender.flushAndGetSequence(): snapshot publishedFsn
    before/after flush, return afterFsn only when it advanced
  • QwpWebSocketSender.drain(): new override using watermark semantics
  • Sender.drain(): updated Javadoc noting implementations may override
    with watermark semantics
  • New tests: testFlushAndGetSequenceReturnsNegativeOneWhenNothingPublished
    and testDrainWaitsForPriorUnackedFrames

Closes #7142

flushAndGetSequence() returned the global published-FSN watermark
instead of -1 when no data was published by the call. This caused
the default Sender.drain() to short-circuit immediately after an
empty flush, even with prior unacked frames still in flight.

- Snapshot publishedFsn before/after flush; return -1 when unchanged
- Override drain() with watermark semantics so it always waits for
  all published frames
- Add deterministic CloseDrainTest with DelayingAckHandler
- Simplify dead afterFsn != -1L guard

Fixes #7142
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