Skip to content

Fix TLS infinite busy loop when write/read handlers are removed#3508

Open
yairgott wants to merge 4 commits intovalkey-io:unstablefrom
yairgott:tls_want_wait
Open

Fix TLS infinite busy loop when write/read handlers are removed#3508
yairgott wants to merge 4 commits intovalkey-io:unstablefrom
yairgott:tls_want_wait

Conversation

@yairgott
Copy link
Copy Markdown
Contributor

When a TLS connection is in a state where it's waiting for a READ during a WRITE (or vice versa), it sets internal flags. If the high-level application removes the write/read handler before the operation completes, these flags were previously left set, causing the connection to remain registered for events that would never be handled, leading to an infinite busy loop in the event loop.

This commit ensures these flags are cleared when handlers are removed.

Added a reproduction test in src/unit/test_tls.c.

Dietr1ch and others added 4 commits April 15, 2026 00:48
…lkey-io#3402)

This allows setting the host and port using environment variables, which
makes using valkey-cli way easier in some development environments. No
need to recall the right host/port, just let your `.env` do the work.

---

Built locally and tested with,

```fish
VALKEY_PORT=36379 ./src/valkey-cli
```

```console
127.0.0.1:36379>
```

And using both,

```fish
VALKEYCLI_HOST=(hostname).local VALKEYCLI_PORT=36379 ./src/valkey-cli
```

```console
<HOSTNAME>.local:36379>
```

Signed-off-by: Dietrich Daroch <Dietrich@Daroch.me>
Signed-off-by: Yair Gottdenker <yairg@google.com>
When a TLS connection is in a state where it's waiting for a READ during a WRITE
(or vice versa), it sets internal flags. If the high-level application removes
the write/read handler before the operation completes, these flags were previously
left set, causing the connection to remain registered for events that would never
be handled, leading to an infinite busy loop in the event loop.

This commit ensures these flags are cleared when handlers are removed.

Added a reproduction test in src/unit/test_tls.c.

Signed-off-by: Yair Gottdenker <yairg@google.com>
When a TLS connection is in a state where it's waiting for a READ during a WRITE
(or vice versa), it sets internal flags. If the high-level application removes
the write/read handler before the operation completes, these flags were previously
left set, causing the connection to remain registered for events that would never
be handled, leading to an infinite busy loop in the event loop.

This commit ensures these flags are cleared when handlers are removed.

Added a reproduction test in src/unit/test_tls.c.

Signed-off-by: Yair Gottdenker <yairg@google.com>
Signed-off-by: Yair Gottdenker <yairg@google.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 58.13953% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.36%. Comparing base (c4db208) to head (7fd39fd).
⚠️ Report is 1 commits behind head on unstable.

Files with missing lines Patch % Lines
src/unit/test_tls.cpp 54.28% 16 Missing ⚠️
src/valkey-cli.c 75.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #3508      +/-   ##
============================================
- Coverage     76.38%   76.36%   -0.03%     
============================================
  Files           159      160       +1     
  Lines         79809    79850      +41     
============================================
+ Hits          60966    60975       +9     
- Misses        18843    18875      +32     
Files with missing lines Coverage Δ
src/tls.c 17.64% <ø> (ø)
src/valkey-cli.c 59.91% <75.00%> (+<0.01%) ⬆️
src/unit/test_tls.cpp 54.28% <54.28%> (ø)

... and 24 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.

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.

2 participants