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

[BUG] Linkdef race condition during provider start #361

Open
brooksmtownsend opened this issue Mar 3, 2022 · 7 comments
Open

[BUG] Linkdef race condition during provider start #361

brooksmtownsend opened this issue Mar 3, 2022 · 7 comments
Labels
bug Something isn't working help wanted Extra attention is needed pinned Should not be removed as stale over time

Comments

@brooksmtownsend
Copy link
Member

Describe the bug

When a capability provider starts there is a period of time between the start of initialization and the time where the provider sets up its nats subscriptions. During this time, link definitions will be lost if they are published.

Background
Capability providers support subscribing link definitions when they are running and accepting a list of link definitions on the stdin stream that the host provides. Inbetween the time where the host opens the capability provider port, giving it a list of link definitions, and when the subscription is setup on the linkdef.put topic then the link definition will be lost until the provider is restarted.

Workaround
This scenario is a very small time window and primarily occurs during situations where starting actors, providers, and putting link definitions is scripted with some concurrency. The simple workaround for this is to publish link definitions before you start capability providers in your scripts in order to always deliver link definitions on provider startup.

Ideal solution
An ideal solution to this problem may be to have the capability provider ask the host for its link definitions rather than receive them on stdin. That way the linkdef.put subscription can already be configured, and the list of linkdefs will be accurate.

@brooksmtownsend brooksmtownsend added bug Something isn't working help wanted Extra attention is needed labels Mar 3, 2022
@stevelr
Copy link
Contributor

stevelr commented Mar 3, 2022

for some background info, when a capability provider receives a put-link, it might do processing such as connect to a remote database, etc. Only after that operation complete successfully is the link added to the provider-maintained list of linked actors. If an RPC is received before that processing has completed, it will report an unlinked actor error.

@stevelr
Copy link
Contributor

stevelr commented Mar 3, 2022

One potential fix would be to have providers return a pass or fail success code response to the linkdef put message. A host should not send a message to a provider unless it has received confirmation that the put link has completed successfully.

@stevelr
Copy link
Contributor

stevelr commented Mar 3, 2022

The suggested workaround ..

publish link definitions before you start capability providers in your scripts in order to always deliver link definitions on provider startup

.. may not work because the provider still needs time to activate the links before it can receive rpc. All the workaround does is move the indeterminate link activation time from the time of put-link to the time of provider start. The race condition would then move to the time between sending a start command and sending rpcs.

@brooksmtownsend
Copy link
Member Author

@stevelr I think we're talking about slightly different race conditions, but correct me if I'm wrong. The two that I see

  1. (this issue) There is a non-zero amount of time between the provider executable starting its main process and when it sets up the NATS subscription to the linkdef.put topic. If a linkdef is put during this time, it's too late for the host to give it to the provider as a part of its HostData, and too early for the provider to receive the message on its own.
  2. (the issue you mention) When a provider receives a linkdef.put, there is a non-zero amount of time between receiving that message and when the provider is truly ready to handle an invocation that corresponds with that linkdef. This can be exacerbated when the provider needs to establish connections, perform computations, etc

@stevelr
Copy link
Contributor

stevelr commented Mar 4, 2022

Thanks for the clarification. I was referring to condition 2, not 1.

@stale
Copy link

stale bot commented May 17, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this has been closed too eagerly, please feel free to tag a maintainer so we can keep working on the issue. Thank you for contributing to wasmCloud!

@stale stale bot added the stale label May 17, 2023
@brooksmtownsend brooksmtownsend added the pinned Should not be removed as stale over time label May 17, 2023
@stale stale bot removed the stale label May 17, 2023
@brooksmtownsend
Copy link
Member Author

I'm pinning this issue because it's a significant bug that we're going to need to address and I don't want to lose it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed pinned Should not be removed as stale over time
Projects
None yet
Development

No branches or pull requests

2 participants