Skip to content

Comments

Bug fix: reset io_last_written on c->buf resize to prevent stale pointers#2786

Merged
hpatro merged 1 commit intovalkey-io:unstablefrom
xbasel:fixCbuf
Oct 30, 2025
Merged

Bug fix: reset io_last_written on c->buf resize to prevent stale pointers#2786
hpatro merged 1 commit intovalkey-io:unstablefrom
xbasel:fixCbuf

Conversation

@xbasel
Copy link
Member

@xbasel xbasel commented Oct 30, 2025

Fixes an assert crash in _writeToClient():

serverAssert(c->io_last_written.data_len == 0 ||
             c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or reallocates c->buf while io_last_written still points to the old buffer and data_len is non-zero. On the next write, both conditions in the assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale pointers and keep state consistent.

fixes #2769

@xbasel xbasel marked this pull request as draft October 30, 2025 19:12
@madolson madolson requested a review from hpatro October 30, 2025 19:17
@madolson madolson moved this to Todo in Valkey 9.0 Oct 30, 2025
…ters

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or reallocates
c->buf while io_last_written still points to the old buffer and data_len is
non-zero. On the next write, both conditions in the assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale pointers
and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Oct 30, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.26%. Comparing base (864de55) to head (8d00054).
⚠️ Report is 1 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2786      +/-   ##
============================================
- Coverage     72.42%   72.26%   -0.16%     
============================================
  Files           128      128              
  Lines         70209    70211       +2     
============================================
- Hits          50847    50740     -107     
- Misses        19362    19471     +109     
Files with missing lines Coverage Δ
src/server.c 88.48% <100.00%> (+<0.01%) ⬆️

... and 13 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@xbasel xbasel marked this pull request as ready for review October 30, 2025 19:51
Copy link
Contributor

@hpatro hpatro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: Don't we need to update any of the other fields of c->io_last_written ?

My bad. It's just the change in reference. data written so far is the same.

@hpatro hpatro merged commit f54818c into valkey-io:unstable Oct 30, 2025
55 checks passed
@github-project-automation github-project-automation bot moved this from Todo to To be backported in Valkey 9.0 Oct 30, 2025
zhijun42 pushed a commit to zhijun42/valkey that referenced this pull request Nov 15, 2025
…ters (valkey-io#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
zhijun42 pushed a commit to zhijun42/valkey that referenced this pull request Nov 15, 2025
…ters (valkey-io#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
zhijun42 pushed a commit to zhijun42/valkey that referenced this pull request Nov 28, 2025
…ters (valkey-io#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
zhijun42 pushed a commit to zhijun42/valkey that referenced this pull request Nov 28, 2025
…ters (valkey-io#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
zhijun42 pushed a commit to zhijun42/valkey that referenced this pull request Nov 28, 2025
…ters (valkey-io#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
@zuiderkwast zuiderkwast moved this from To be backported to 9.0.1 (WIP) in Valkey 9.0 Dec 4, 2025
zuiderkwast pushed a commit to zuiderkwast/placeholderkv that referenced this pull request Dec 4, 2025
…ters (valkey-io#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes valkey-io#2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
zuiderkwast pushed a commit that referenced this pull request Dec 9, 2025
…ters (#2786)

Fixes an assert crash in _writeToClient():

    serverAssert(c->io_last_written.data_len == 0 ||
                 c->io_last_written.buf == c->buf);

The issue occurs when clientsCronResizeOutputBuffer() grows or
reallocates c->buf while io_last_written still points to the old buffer
and data_len is non-zero. On the next write, both conditions in the
assertion become false.

Reset io_last_written when resizing the output buffer to prevent stale
pointers and keep state consistent.

fixes #2769

Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 9.0.1

Development

Successfully merging this pull request may close these issues.

[CRASH] Assertion failure in networking.c after upgrading from 8.1.4 to 9.0.0 (PUB/SUB, I/O threads enabled)

2 participants