Skip to content

Conversation

@CagriYonca
Copy link
Contributor

  • The state machine was not compatible with multi-threads by default. Every fork was changing the state of the fysom so that Fysom was falling into fysom.FysomError: event announce inappropriate in current state announced error. After adding a thread-safe lock mechanism, it works and propagates spans as expected.
  • Verified that the instrumentation works even without hooks.

@CagriYonca CagriYonca self-assigned this Jan 7, 2026
@CagriYonca CagriYonca requested a review from a team as a code owner January 7, 2026 09:57
@CagriYonca CagriYonca added the bug label Jan 7, 2026
@CagriYonca CagriYonca changed the title Gunicorn INSTA-69727 - Fysom improvement for multi-threaded operations Jan 7, 2026
@CagriYonca
Copy link
Contributor Author

The code is tested for gunicorn in amd64, arm64 and with autotrace-webhook.

@CagriYonca CagriYonca changed the title INSTA-69727 - Fysom improvement for multi-threaded operations [INSTA-69727] Fysom improvement for multi-threaded operations Jan 12, 2026
@CagriYonca CagriYonca force-pushed the fix-gunicorn branch 3 times, most recently from e57efa4 to 8970564 Compare January 16, 2026 08:46
Copy link
Contributor

@GSVarsha GSVarsha left a comment

Choose a reason for hiding this comment

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

Suggested changes.

Copy link
Contributor

@GSVarsha GSVarsha left a comment

Choose a reason for hiding this comment

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

Few suggestions

@CagriYonca CagriYonca force-pushed the fix-gunicorn branch 2 times, most recently from e46e111 to 7e6ce54 Compare February 9, 2026 11:43
@CagriYonca CagriYonca requested a review from GSVarsha February 9, 2026 11:43
Forks happen. Here we handle them.
"""
# Update boot PID to current PID to prevent duplicate fork detection
self._boot_pid = os.getpid()
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this variable is not used anywhere. Am I wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't change anything regarding _boot_pid variable but it's used in can_send method to perform fork detection.

Comment on lines +464 to +465
if lock_acquired:
self.collector.background_report_lock.release()
Copy link
Member

Choose a reason for hiding this comment

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

I may not be following correctly, but why are you releasing the lock in a function that mainly prints a diagnostic of the agent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally, we were using the locked() method to check if the background_report_check is locked or not but as we moved to RLock, this new object doesn't have this method. We acquire the thread without blocking and release it immediately.

…nstrumentation

Signed-off-by: Cagri Yonca <cagri@ibm.com>
@sonarqubecloud
Copy link

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants