Skip to content

Conversation

@copybara-service
Copy link

netstack: Use ctx.BlockWithTimeout() directly while releasing socket.

When ctx is of type kernel.taskAsyncContext, calling
kernel.TaskFromContext(ctx) on it returns the original task (even though this
is an async goroutine). And then calling methods like Block() on it would panic
because it expects to be running on the task goroutine. Furthermore, the Task
could have exited so working on a dead task could cause other issues too.

Instead, use kernel.taskAsyncContext methods via the context.Context
interface. This change adds BlockWithTimeout() to the context interface and
implements it for context.NoTask. kernel.Task already implements this.

The current implementation of context.NoTask.BlockWithTimeoutOn was buggy:

  • It returned true when the desired event occurred OR when the timeout expired.
    However, context.Blocker interface docstring suggest that true should only
    be returned when the desired event occurs, which kernel.Task implements
    correctly.
  • Instead of returning the remaining timeout, it returned the duration passed
    since the timer started.

Fixed these two bugs and made the implementations of kernel.Task and
context.NoTask consistent with one another.

Also clarified docstrings for some Task.Block*() methods about the precondition
of "The caller must be running on the task goroutine.".

Reported-by: [email protected]
Reported-by: [email protected]

@copybara-service copybara-service bot added the exported Issue was exported automatically label Jan 7, 2026
@copybara-service copybara-service bot force-pushed the test/cl853345768 branch 3 times, most recently from f02aaba to 89a67f6 Compare January 8, 2026 04:57
When ctx is of type `kernel.taskAsyncContext`, calling
`kernel.TaskFromContext(ctx)` on it returns the original task (even though this
is an async goroutine). And then calling methods like Block() on it would panic
because it expects to be running on the task goroutine. Furthermore, the Task
could have exited so working on a dead task could cause other issues too.

Instead, use `kernel.taskAsyncContext` methods via the context.Context
interface. This change adds BlockWithTimeout() to the context interface and
implements it for context.NoTask. kernel.Task already implements this.

The current implementation of context.NoTask.BlockWithTimeoutOn was buggy:
- It returned true when the desired event occurred OR when the timeout expired.
  However, context.Blocker interface docstring suggest that true should only
  be returned when the desired event occurs, which kernel.Task implements
  correctly.
- Instead of returning the remaining timeout, it returned the duration passed
  since the timer started.

Fixed these two bugs and made the implementations of kernel.Task and
context.NoTask consistent with one another.

Also clarified docstrings for some Task.Block*() methods about the precondition
of "The caller must be running on the task goroutine.".

Reported-by: [email protected]
Reported-by: [email protected]
PiperOrigin-RevId: 853557307
@copybara-service copybara-service bot merged commit 2f53776 into master Jan 8, 2026
0 of 2 checks passed
@copybara-service copybara-service bot deleted the test/cl853345768 branch January 8, 2026 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

exported Issue was exported automatically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant