Skip to content

fix(async): potential UB in the scheduler implementation #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 22, 2025

Conversation

bavshin-f5
Copy link
Member

The way we accessed UnsafeCell in the posted event handler was oddly similar to the bad example in the reference1.

It's not an exact match since we don't have a shared reference to the cell, but I'd still prefer to use the documented way to access the underlying data.

The way we accessed UnsafeCell in the posted event handler was oddly
similar to the bad example in the reference[1].

It's not an exact match since we don't have a _shared_ reference to the
cell, but I'd still prefer to use the documented way to access the
underlying data.

[1]: https://doc.rust-lang.org/stable/std/cell/struct.UnsafeCell.html#memory-layout
@bavshin-f5 bavshin-f5 requested a review from Copilot July 21, 2025 16:46
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a potential undefined behavior (UB) issue in the async scheduler implementation by correcting how UnsafeCell is accessed. The change ensures compliance with Rust's documented safe patterns for UnsafeCell usage, moving away from a pattern that resembled problematic examples in the official documentation.

  • Updates the Scheduler struct to wrap SchedulerInner in UnsafeCell at construction time
  • Modifies the event handler to use the documented UnsafeCell::raw_get() method for safe access
  • Improves safety documentation with clearer explanation and reference to official guidelines

@bavshin-f5 bavshin-f5 merged commit c3a5941 into nginx:main Jul 22, 2025
15 checks passed
@bavshin-f5 bavshin-f5 deleted the unsafe-cell-ub branch July 22, 2025 00:57
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.

3 participants