Skip to content
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

fix: better error handling in SendWork #412

Merged
merged 4 commits into from
Jul 12, 2024
Merged

fix: better error handling in SendWork #412

merged 4 commits into from
Jul 12, 2024

Conversation

teslashibe
Copy link
Contributor

@teslashibe teslashibe commented Jul 11, 2024

Fix Nil Pointer Dereference in SendWork Function for #408

This closes #408

Description

This PR addresses a critical bug in the SendWork function within the workers.go file, where a nil pointer dereference panic occurs under certain conditions. The issue was identified in the remote worker spawning logic, specifically when the SpawnNamed method returns a nil PID *actor.PID, and subsequent operations attempt to use this nil pointer, leading to a runtime panic.

Changes

  • Nil Check for spawnedPID: Added a nil check immediately after attempting to spawn a new actor with SpawnNamed. If spawnedPID is nil, the function logs an error and returns early from the goroutine, preventing the nil pointer dereference.
  • Correct Loop Variable Capture: Modified the anonymous goroutine function within the loop to take the loop variable [p] as a parameter. This change ensures that each goroutine receives the correct instance of [p], avoiding potential issues with loop variable capture in goroutines.

Impact

  • Reliability: This fix prevents the worker from crashing due to a nil pointer dereference, thus improving the overall reliability of the worker's operation.
  • Error Handling: By adding proper error handling and logging, the system can now gracefully handle scenarios where remote actor spawning fails, allowing for better diagnosis and maintenance.
  • Concurrency Safety: Correcting the loop variable capture in goroutines ensures that concurrent operations behave as expected, without unintended side effects.

@teslashibe teslashibe self-assigned this Jul 11, 2024
@teslashibe teslashibe requested a review from mudler July 11, 2024 22:48
Copy link
Contributor

@mudler mudler left a comment

Choose a reason for hiding this comment

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

Looking good! just few minor nits as in the other PRs, but nothing blocking.

@mudler mudler changed the title Fix Nil Pointer Dereference in SendWork Function for #408 fix: better error handling in SendWork Jul 12, 2024
@mudler mudler merged commit 5680523 into test Jul 12, 2024
1 of 3 checks passed
@mudler mudler deleted the teslashibe/#408 branch July 12, 2024 07:34
@mudler mudler added the bug Something isn't working label Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: panic when worker actor start picking up jobs
2 participants