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 pan domain settings refresher #41

Merged
merged 2 commits into from
Feb 20, 2018
Merged

Fix pan domain settings refresher #41

merged 2 commits into from
Feb 20, 2018

Conversation

alexduf
Copy link

@alexduf alexduf commented Feb 19, 2018

The actor system was instantiated for each controller. This changed when
the actor system was passed down as a parameter, which in turn created
more problems as the domain settings refresher was instantiated for
each controller leading to a name collision.

This attempts to fix it by extracting the refresher logic out of the
trait, and requiring it to be injected in each controller

cc @regiskuckaertz

The actor system was instantiated for each controller. This changed when
the actor system was passed down as a parameter, which in turn created
more problems as the domain settings refresher was instantiated for
each controller leading to a name collision.

This attempts to fix it by extracting the refresher logic out of the
trait, and requiring it to be injected in each controller
@alexduf alexduf requested a review from adamnfish February 19, 2018 17:18
@regiskuckaertz
Copy link

it looks good to me 👍 I just wonder if it would be cleaner if the actor was created in a method that receives an Actor System, with another one to kill it on exit for good measure?

@regiskuckaertz
Copy link

regiskuckaertz commented Feb 20, 2018

Scratch that, the sole purpose is to create that actor so no need to delay passing the system in.

@alexduf
Copy link
Author

alexduf commented Feb 20, 2018

Cool, also passing the actor system managed by Play means when the app is turned off by play (including in dev mode) the actor system will be brought down the right way.

@regiskuckaertz do you want to do a release local and test it before I merge and release?

@regiskuckaertz
Copy link

Yep, doing it right now

@regiskuckaertz
Copy link

All good 🚢

@alexduf alexduf merged commit 4b6ad19 into master Feb 20, 2018
@alexduf alexduf deleted the fix-settings-refresher branch February 20, 2018 11:00
rtyley added a commit that referenced this pull request Sep 12, 2024
Having `def panDomainSettings: PanDomainAuthSettingsRefresher` in the `AuthActions`
trait as a `def` means that implementors of `AuthActions` are able to make the
mistake of also defining their implementation of that field as a `def`, meaning that
every reference to it can potentially create _another_ instance of the refresher,
as seen here:

guardian/atom-workshop#361 (comment)

Surprisingly, this seems to have been a problem since at least as far back as
#41 in February 2018.

Changing the field type to `val` forces implementers to also use `val` for that
field, effectively making it a singleton, as we want.

Changing the abstract field of a trait to be `val` does open up another danger due
the initialization order of vals - the field could end up being evaluated as
`null` if the trait immediately evaluates the field:

See: https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html

...consequently, I've made all `val` declarations in the `AuthActions` trait (that
evaluate `panDomainSettings` in some way) into `lazy val`s. This hopefully should
fix the problem.
rtyley added a commit that referenced this pull request Sep 12, 2024
Having `def panDomainSettings: PanDomainAuthSettingsRefresher` in the `AuthActions`
trait as a `def` means that implementors of `AuthActions` are able to make the
mistake of also defining their implementation of that field as a `def`, meaning that
every reference to it can potentially create _another_ instance of the refresher,
as seen here:

guardian/atom-workshop#361 (comment)

Surprisingly, this seems to have been a problem since at least as far back as
#41 in February 2018.

Changing the field type to `val` forces implementers to also use `val` for that
field, effectively making it a singleton, as we want.

Changing the abstract field of a trait to be `val` does open up another danger due
the initialization order of vals - the field could end up being evaluated as
`null` if the trait immediately evaluates the field:

See: https://docs.scala-lang.org/tutorials/FAQ/initialization-order.html

...consequently, I've made all `val` declarations in the `AuthActions` trait (that
evaluate `panDomainSettings` in some way) into `lazy val`s. This hopefully should
fix the problem.
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.

2 participants