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

store root dispatcher in a static var #780

Merged
merged 3 commits into from
Jul 19, 2022
Merged

store root dispatcher in a static var #780

merged 3 commits into from
Jul 19, 2022

Conversation

brettmc
Copy link
Collaborator

@brettmc brettmc commented Jul 19, 2022

This seems to be the safest way to store the main dispatcher. Using context to store the main event dispatcher causes a scope to be created: activating the newly-created context which stores dispatcher causes a new scope, and that can break things.
I also looked at storing dispatcher in the root context, but that can't work because contexts are immutable.

Closes #778

This seems to be the safest way to store the main dispatcher. Using context to store the main event dispatcher causes a scope to be created: activating the newly-created context which stores dispatcher causes a new scope, and that can break things.
I also looked at storing dispatcher in the root context, but that can't work because contexts are immutable.
@codecov
Copy link

codecov bot commented Jul 19, 2022

Codecov Report

Merging #780 (9c0d7e8) into main (5a64c0d) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

❗ Current head 9c0d7e8 differs from pull request most recent head 8f76d2a. Consider uploading reports for the commit 8f76d2a to get more accurate results

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #780      +/-   ##
============================================
- Coverage     79.53%   79.49%   -0.05%     
+ Complexity     1409     1407       -2     
============================================
  Files           160      160              
  Lines          3479     3472       -7     
============================================
- Hits           2767     2760       -7     
  Misses          712      712              
Flag Coverage Δ
7.4 79.49% <100.00%> (-0.05%) ⬇️
8.0 79.56% <100.00%> (-0.05%) ⬇️
8.1 79.56% <100.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/API/Common/Event/Dispatcher.php 100.00% <100.00%> (ø)
src/API/Common/Event/EmitsEventsTrait.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a64c0d...8f76d2a. Read the comment docs.

/** @var array<string, array<int, array<callable>>> */
private array $listeners = [];

public static function getInstance(): self
public static function getRoot(): self
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I chose root because it sounds less singleton-y, since you can in fact have as many dispatchers as you wish. This is just the default one.

@tidal
Copy link
Member

tidal commented Jul 19, 2022

Oki.
I will take care of providing a static referenceto the dispatcher with the API/SDK anyway (soone done) , because that's needed for the instrumentations. However it doesn't hurt if it has its ownone.

@tidal tidal merged commit 08c9180 into open-telemetry:main Jul 19, 2022
@brettmc brettmc deleted the bugfix/dispatcher-leaks-scope branch October 25, 2022 06: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.

Event\Dispatcher::getInstance() leaks scope
2 participants