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

Allowing session declarations to stay alive for the lifespan of a session. #96

Merged

Conversation

DariusIMP
Copy link
Member

Zenoh declarations ran for as long as the Kotlin variable representing them was kept alive. This meant that whenever the user lost track of the variable, it got garbage collected and undeclared in the process. This behavior seems to be counterintuitive for programmers used to garbage collected languages (see #43).

Therefore in this PR we provide the following change: we keep track of session declarations in a list inside the session, allowing users to keep running them despite losing their references. When the session is finalized, the associated declarations are undeclared. In case the user needs to close a declaration earlier, they need to keep the variable in order to undeclare it.

@DariusIMP DariusIMP marked this pull request as draft May 14, 2024 13:22
@hassomehide
Copy link

@DariusIMP any chance this PR makes it to the 1.0 release?

I am mainly interested because of the removal of finalize() overrides in the declaration classes. Although I am worried because the Subscriber class seems to still have it.

I have encountered several JVM crashes caused by a SIGSEGV because I have closed a session without undeclaring subscribers first, resulting in the subscribers attempting to undeclare themselves afterwards when they are being garbage collected.

I can also create a separate issue for that JVM crash but it seems that this PR should fix the problem (if all declaration classes get rid of the finalize method), as well as provide an easier-to-use API. Because currently I have to wrap the Session with my own class in order to keep track of the closeables.

@DariusIMP
Copy link
Member Author

@hassomehide Yes, this will be added to the next release

@DariusIMP DariusIMP changed the base branch from main to dev/1.0.0 August 1, 2024 07:51
@DariusIMP DariusIMP force-pushed the issue/background-declarations branch from e54d723 to 66b5dd6 Compare August 1, 2024 09:21
@DariusIMP DariusIMP marked this pull request as ready for review August 1, 2024 09:47
@DariusIMP DariusIMP force-pushed the issue/background-declarations branch from 66b5dd6 to 808a42e Compare August 1, 2024 09:50
…alive for the lifespan of a session.

Zenoh declarations ran for as long as the Kotlin variable representing them was kept alive. This
meant that whenever the user lost track of the variable, it got garbage collected and undeclared
in the process. This behavior seems to be counterintuitive for programmers used to garbage collected
languages (see eclipse-zenoh#43).

Therefore in this PR we provide the following change: we keep track of session declarations in a list
inside the session, allowing users to keep running them despite losing their references.
When the session is finalized, the associated declarations are undeclared.
In case the user needs to close a declaration earlier, they need to keep the variable in order
to undeclare it.
@DariusIMP DariusIMP force-pushed the issue/background-declarations branch from 808a42e to 7fe1fdf Compare August 1, 2024 10:25
@DariusIMP DariusIMP force-pushed the issue/background-declarations branch from f4e7366 to ca1ea92 Compare August 1, 2024 11:02
@gabrik gabrik merged commit 19171df into eclipse-zenoh:dev/1.0.0 Aug 1, 2024
6 checks passed
DariusIMP added a commit to ZettaScaleLabs/zenoh-kotlin that referenced this pull request Aug 5, 2024
…sion. (eclipse-zenoh#96)

* feat(background declarations): Allowing session declarations to stay alive for the lifespan of a session.

Zenoh declarations ran for as long as the Kotlin variable representing them was kept alive. This
meant that whenever the user lost track of the variable, it got garbage collected and undeclared
in the process. This behavior seems to be counterintuitive for programmers used to garbage collected
languages (see eclipse-zenoh#43).

Therefore in this PR we provide the following change: we keep track of session declarations in a list
inside the session, allowing users to keep running them despite losing their references.
When the session is finalized, the associated declarations are undeclared.
In case the user needs to close a declaration earlier, they need to keep the variable in order
to undeclare it.

* feat(background declarations): closing all session declarations immediately after doing `session.close()`
DariusIMP added a commit to ZettaScaleLabs/zenoh-kotlin that referenced this pull request Aug 5, 2024
…sion. (eclipse-zenoh#96)

* feat(background declarations): Allowing session declarations to stay alive for the lifespan of a session.

Zenoh declarations ran for as long as the Kotlin variable representing them was kept alive. This
meant that whenever the user lost track of the variable, it got garbage collected and undeclared
in the process. This behavior seems to be counterintuitive for programmers used to garbage collected
languages (see eclipse-zenoh#43).

Therefore in this PR we provide the following change: we keep track of session declarations in a list
inside the session, allowing users to keep running them despite losing their references.
When the session is finalized, the associated declarations are undeclared.
In case the user needs to close a declaration earlier, they need to keep the variable in order
to undeclare it.

* feat(background declarations): closing all session declarations immediately after doing `session.close()`
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