Skip to content

fix(proto): Avoid active_connections underflow#717

Merged
matheus23 merged 1 commit into
mainfrom
matheus23/active-connections
Jun 22, 2026
Merged

fix(proto): Avoid active_connections underflow#717
matheus23 merged 1 commit into
mainfrom
matheus23/active-connections

Conversation

@matheus23

Copy link
Copy Markdown
Member

Description

Fixes an underflow panic on decrementing active_connections in the noq endpoint state.
This occurred when the API was used in this order:

  1. client connects to server
  2. server calls Endpoint::accept and captures the Incoming
  3. server endpoint closes using Endpoint::close
  4. server side calls Incoming::accept on the captured incoming
  5. (EndpointDriver will panic)

The reason for this was that incrementing and decrementing the active_connections was asymmetrical.
We would increment active_connections only if the endpoint wasn't closed yet. However, we would decrement unconditionally, eventually underflowing.

This PR removes the condition for incrementing. This preserves the behavior of being able to accept Incomings after calling Endpoint::close. This is somewhat unlike what the iroh API expects (because in iroh you can't do anything with the endpoint after Endpoint::close), but noq's API is just different.

This also adds a regression test that fails without the fix. That needs a PanicPropagatingRuntime implementation and some test helpers to allow for configuring that though...

Breaking Changes

None

Notes & open questions

Disclosure: Heavily assisted with GLM 5.2.

Change checklist

  • Self-review.
  • Tests if relevant.
  • All breaking changes documented.

@matheus23
matheus23 requested a review from flub June 19, 2026 13:06
@matheus23 matheus23 self-assigned this Jun 19, 2026
@matheus23 matheus23 added this to iroh Jun 19, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Jun 19, 2026
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

Documentation for this PR has been generated and is available at: https://n0-computer.github.io/noq/pr/717/docs/noq/

Last updated: 2026-06-19T13:17:19Z

@matheus23 matheus23 moved this from 🚑 Needs Triage to 🏗 In progress in iroh Jun 19, 2026
@matheus23 matheus23 moved this from 🏗 In progress to 👍 Ready in iroh Jun 19, 2026
@matheus23 matheus23 moved this from 👍 Ready to 👀 In review in iroh Jun 19, 2026
@matheus23
matheus23 force-pushed the matheus23/active-connections branch from 35ad58a to 6e759e3 Compare June 19, 2026 13:14
@github-actions

github-actions Bot commented Jun 19, 2026

Copy link
Copy Markdown

Performance Comparison Report

35ad58aa843942fd167e3ba8cedb2882643ce3d8 - artifacts

Raw Benchmarks (localhost)

Scenario noq upstream Delta CPU (avg/max)
large-single 5178.4 Mbps 7976.3 Mbps -35.1% 95.5% / 100.0%
medium-concurrent 5312.1 Mbps 7860.8 Mbps -32.4% 97.3% / 153.0%
medium-single 4425.7 Mbps 4749.6 Mbps -6.8% 97.3% / 151.0%
small-concurrent 3893.3 Mbps 5212.9 Mbps -25.3% 94.0% / 103.0%
small-single 3561.9 Mbps 4757.5 Mbps -25.1% 92.1% / 102.0%

Netsim Benchmarks (network simulation)

Condition noq upstream Delta
ideal 3009.6 Mbps N/A N/A
lan 782.4 Mbps N/A N/A
wan 83.8 Mbps N/A N/A

Summary

noq is 26.8% slower on average

---
6e759e37de31625a6930adcfa195f6e2da255a9e - artifacts

Raw Benchmarks (localhost)

Scenario noq upstream Delta CPU (avg/max)
large-single 5494.7 Mbps 7799.8 Mbps -29.6% 96.0% / 97.9%
medium-concurrent 5277.8 Mbps 7650.3 Mbps -31.0% 96.2% / 97.8%
medium-single 3846.6 Mbps 4749.1 Mbps -19.0% 96.2% / 98.2%
small-concurrent 3711.3 Mbps 5173.5 Mbps -28.3% 96.1% / 98.9%
small-single 3513.6 Mbps 4836.3 Mbps -27.4% 96.0% / 98.1%

Netsim Benchmarks (network simulation)

Condition noq upstream Delta
ideal 3100.6 Mbps 3799.2 Mbps -18.4%
lan 782.3 Mbps 810.4 Mbps -3.5%
lossy 69.8 Mbps 55.9 Mbps +25.0%
wan 83.8 Mbps 83.8 Mbps ~0%

Summary

noq is 26.0% slower on average

@matheus23
matheus23 added this pull request to the merge queue Jun 22, 2026
Merged via the queue into main with commit 32467e4 Jun 22, 2026
39 checks passed
@matheus23
matheus23 deleted the matheus23/active-connections branch June 22, 2026 13:57
@github-project-automation github-project-automation Bot moved this from 👀 In review to ✅ Done in iroh Jun 22, 2026
@JssDWt

JssDWt commented Jun 26, 2026

Copy link
Copy Markdown

@matheus23 I just ran into this scenario. Thanks for fixing. Do you have a timeline when this will end up in a release?

@matheus23

Copy link
Copy Markdown
Member Author

Plan is Monday. But let's tentatively say next week :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants