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

mdsdisconnect in the IDL API does not correctly return the optional status value #2640

Open
mwinkel-dev opened this issue Oct 12, 2023 · 2 comments
Assignees
Labels
api/idl Relates to the IDL API bug An unexpected problem or unintended behavior

Comments

@mwinkel-dev
Copy link
Contributor

mwinkel-dev commented Oct 12, 2023

Affiliation
MIT PSFC

Version(s) Affected
all

Platform
Found in Ubuntu 20, but surely affects all platforms

Describe the bug
In the IDL API, the mdsdisconnect routine can return an optional status value. It is not properly comparing the results from the underlying C code in mdsipshr, thus always returns zero (failure).

To Reproduce
Steps to reproduce the behavior:

At the IDL prompt, run the following procedure. Note that mystatus is always zero.

; Demonstrates that mdsdisconnect does not correctly return the optional status value
pro bug_2640 
   mdsip_server = 'some_server'

   ; socket 0
   mdsconnect, mdsip_server
   print, !MDS_SOCKET

   ; Successfully kills socket, but erroneously reports status = 0 (failure)
   mystatus = -77
   mdsdisconnect, socket=0, status=mystatus
   print, !MDS_SOCKET, mystatus

   ; Socket already killed, so correctly reports status = 0
   mystatus = -77
   mdsdisconnect, socket=0, status=mystatus
   print, !MDS_SOCKET, mystatus
end

Output of the program (with a debug print statement in mdsdisconnect.pro) follows.

IDL> bug_2640
% Compiled module: BUG_2640.
% Compiled module: MDSCONNECT.
% Compiled module: MDS_KEYWORD_SET.
% Compiled module: MDSDISCONNECT.
       0
XMW mdsdisconnect - status after call_external =        65545
       0       0
XMW mdsdisconnect - status after call_external =        65554
       0       0
IDL>

Then examine mdsshr_messages.h and note the following:

  • decimal 65545 = hex 0x10009 = MDSplusSUCCESS
  • decimal 65554 = hex 0x110012 = MDSplusERROR

The problem is caused by these two lines of mdsdisconnect.pro and the incorrect comparison. (At the top of the routine, status is initialized to 1, which is likely intended to denote success. And thus 0 denotes failure.)

status = call_external(image,'DisconnectFromMds',sock,value=[1b], /AUTO_GLUE)
if (status eq 0) then status = 1 else status = 0

Expected behavior
When running the above program, the first mdsdisconnect should return the success status (i.e., one), and the second mdsdisconnect should return the failure status (i.e., zero).

Screenshots
n/a

Additional context
This is apparently a low risk bug. If customers used the status feature of mdsdisconnect, this bug would have been filed years ago.

Also Investigate
All call_external calls in the IDL API should be investigated for similar issues regarding the status code returned by the underlying C libraries. A cursory scan of the IDL API revealed these likely trouble spots:

  • mds$disconnect in mdsconnect.pro
  • mdslogin.pro
  • mdsvalue.pro
@mwinkel-dev mwinkel-dev added bug An unexpected problem or unintended behavior api/idl Relates to the IDL API labels Oct 12, 2023
@mwinkel-dev mwinkel-dev self-assigned this Oct 12, 2023
@ModestMC
Copy link

Nice find!

@mwinkel-dev
Copy link
Contributor Author

mwinkel-dev commented Oct 19, 2023

When this bug is fixed, uncomment all IDL-2640-* tests in the IDL test harness (idl/testing/run_tests.py).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api/idl Relates to the IDL API bug An unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants