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

Calling nidaqmx GetExtendedErrorInfo via gRPC is not reliable because it uses thread-local storage #684

Closed
bkeryan opened this issue Jul 21, 2022 · 1 comment

Comments

@bkeryan
Copy link
Contributor

bkeryan commented Jul 21, 2022

nidaqmx.proto supports the DAQmxGetExtendedErrorInfo function. Calling this function via gRPC is not reliable because it uses thread-local storage.

Depending which server thread is used to handle this request, it may return the correct error message, an empty string, or an incorrect error message.

Steps to reproduce:

  1. Change one of the DAQmx examples to make multiple concurrent GetExtendedErrorInfo requests:
def raise_if_error(response):
    """Raise an exception if an error was returned."""
    if response.status != 0:
        response = client.GetExtendedErrorInfo.future(nidaqmx_types.GetExtendedErrorInfoRequest())
        response2 = client.GetExtendedErrorInfo.future(nidaqmx_types.GetExtendedErrorInfoRequest())
        response3 = client.GetExtendedErrorInfo.future(nidaqmx_types.GetExtendedErrorInfoRequest())
        raise Exception(f"Error: {response3.result().error_string}")
  1. Run NI IO Trace and enable the ThreadID column.
  2. Run the example with an invalid device identifier. Normally, this would display a "Device identifier is invalid" error, but this issue may cause it to display an empty string or an incorrect error message.
(.venv) PS Z:\grpc-device\examples\nidaqmx> python .\analog-input.py localhost 31763 Dev42/ai0
Traceback (most recent call last):
  File ".\analog-input.py", line 71, in <module>
    raise_if_error(
  File ".\analog-input.py", line 63, in raise_if_error
    raise Exception(f"Error: {response3.result().error_string}")
Exception: Error: The requested memory could not be allocated.
Status Code: -50352

NI IO Trace will show which thread was used to handle each call to DAQmxGetExtendedErrorInfo:
image

AB#2085088

@bkeryan
Copy link
Contributor Author

bkeryan commented Oct 19, 2022

I validated that GetExtendedErrorInfo has been removed from nidaqmx.proto and is called from NiDAQmxService::ConvertApiErrorStatusForTaskHandle, which should always be called on the same thread that returned the error.

@bkeryan bkeryan closed this as completed Oct 19, 2022
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

No branches or pull requests

1 participant