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

Dont signal occurrence if client call not active #223

Closed
wants to merge 2 commits into from

Conversation

ni-sujain
Copy link
Collaborator

@ni-sujain ni-sujain commented Jan 27, 2023

fix for issue #217

The issue is that client can run into a situation where an inactive client call(e.g. due to vi aborts) will end up signaling the lv occurrence from async thread for an active client call(occurrence is getting re-used) and "wait for occurrence" unblocks without reading the response from server and we will see no response for the active call.

The fix involves clearing the active client calls list on vi abort and signal occurrence only when the current call is active. This fix will work for most cases but it still can run into some race conditions.

Alternatives considered:

  • Somehow reset the occurrence on vi abort. Could not find a way to do this. Even if a signal the occurrence in ClientCleanupProc it doesnot work.
  • Reset occurrence before we run ClientUnaryCall CLFN node. Tried Wait on occurrence primitive with zero timeout, Set occurence primitve but they also did not work. as even if we reset, the async c++ can signal before we go inside new ClientUnaryCall CLFN.
  • Do a wait() on blocking client call but this takes away some async behavior.

testing:
I tried with the attached example from the issue. It runs fine.

@shivaprasad-basavaraj
Copy link
Collaborator

We should add this scenario as an auto test as well.

@@ -192,6 +193,22 @@ int32_t CloseClient(grpc_labview::LabVIEWgRPCClient* client)
return 0;
}

// Signal a lv occurence for a client call from async c++ thread
void SignalOccurenceForClientCall(grpc_labview::ClientCall* clientCall)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we name this method CheckActiveAndSignalOccurence to signify that we will fire the occurrence only if the client call is active?

src/grpc_client.cc Show resolved Hide resolved
@ni-sujain
Copy link
Collaborator Author

Note: This PR still need some work. There are test failures for streaming cases

@drjdpowell
Copy link

Just a FYI, but this is another reason (beyond #207) to be wary of using Occurances rather than a Queue. Queues, like most LabVIEW refnums, can be created and destroyed, and have a lifetime tied to the creating VI hierarchy, meaning they are cleaned up automatically when the VI is aborted, and any refnum passed to other code becomes invalid (yet safe to call). This prevents all kinds of problems and can allow race-condition free code.

Occurances are seemingly simple low-level things, but they can be tricky to use, because they don't have a controlled "lifetime". You can't "clean it up and create a fresh one" to solve your corner case like an aborted VI.

@ni-sujain
Copy link
Collaborator Author

ni-sujain commented May 2, 2023

See PR #251

@ni-sujain ni-sujain closed this May 2, 2023
@ni-sujain ni-sujain deleted the master-fork-dev-local branch May 3, 2023 09:04
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