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

[carta python] backend crash due to session id in the interact mode #1248

Closed
kswang1029 opened this issue Mar 17, 2023 · 2 comments · Fixed by #1249
Closed

[carta python] backend crash due to session id in the interact mode #1248

kswang1029 opened this issue Mar 17, 2023 · 2 comments · Fixed by #1249
Assignees
Labels
bug Something isn't working

Comments

@kswang1029
Copy link
Contributor

Describe the bug
with the scripting interface, if we do
session = Session.interact(url_with_token, session_id, debug_no_auth=True)
with a correct session_id, things work normally.

But if `session_id` is not correct, we see error from the scripting interface like
Traceback (most recent call last):
  File "/Users/kswang/carta_pythonInterface_testing/test.py", line 23, in <module>
    img0 = session.open_image(image_file_0)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/validation.py", line 630, in newfunc
    return func(self, *args, **kwargs)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/session.py", line 371, in open_image
    return Image.new(self, path, hdu, False)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/image.py", line 68, in new
    image_id = session.call_action("appendFile" if append else "openFile", directory, file_name, hdu, return_path="frameInfo.fileId")
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/session.py", line 250, in call_action
    return self._protocol.request_scripting_action(self.session_id, path, *args, **kwargs)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/protocol.py", line 362, in request_scripting_action
    raise CartaRequestFailed(f"{carta_action_description} failed with status {response.status_code}. {backend_message}")
carta.util.CartaRequestFailed: CARTA scripting action .openFile called with parameters ('/Users/kswang/carta_image_pool/set_HD163296', 'HD163296_CO_2_1.fits', '') failed with status 404. No session with ID 1070215517 could be found.

and the backend is still alive. However, if we correct the session_id and re-run the script, the backend will crash with a Segmentation fault: 11.

the macOS crash report is

Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000118
Exception Codes: 0x0000000000000001, 0x0000000000000118
Exception Note: EXC_CORPSE_NOTIFY

Termination Reason: Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process: exc handler [15944]

VM Region Info: 0x118 is not in any region. Bytes before following region: 140737487199976
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
VM_ALLOCATE 7fffffee6000-7fffffee7000 [ 4K] r-x/r-x SM=ALI

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libc++.1.dylib 0x7ff8031aaa71 std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >::basic_string(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, unsigned long, unsigned long, std::__1::allocator const&) + 23
1 carta_backend 0x102b484b4 casacore::String::String(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, unsigned long, unsigned long) + 14 (String.h:257) [inlined]
2 carta_backend 0x102b484b4 casacore::String::String(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, unsigned long, unsigned long) + 14 (String.h:257) [inlined]
3 carta_backend 0x102b484b4 GetResolvedFilename(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) + 52 (Casacore.cc:104)
4 carta_backend 0x102b05a94 carta::Session::CloseCachedImage(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) + 36 (Session.cc:2257)
5 carta_backend 0x102b0fc94 carta::SessionManager::OnMessage(uWS::WebSocket<false, true, carta::PerSocketData>, std::__1::basic_string_view<char, std::__1::char_traits >, uWS::OpCode) + 3684 (SessionManager.cc:258)
6 carta_backend 0x102b178e4 ofats::any_detail::any_invocable_impl<void, false, uWS::WebSocket<false, true, carta::PerSocketData>
, std::__1::basic_string_view<char, std::__1::char_traits >, uWS::OpCode>::call(uWS::WebSocket<false, true, carta::PerSocketData>, std::__1::basic_string_view<char, std::__1::char_traits >, uWS::OpCode) + 17 (MoveOnlyFunction.h:247) [inlined]
7 carta_backend 0x102b178e4 ofats::any_invocable<void (uWS::WebSocket<false, true, carta::PerSocketData>
, std::__1::basic_string_view<char, std::__1::char_traits >, uWS::OpCode)>::operator()(uWS::WebSocket<false, true, carta::PerSocketData>, std::__1::basic_string_view<char, std::__1::char_traits >, uWS::OpCode) + 17 (MoveOnlyFunction.h:354) [inlined]
8 carta_backend 0x102b178e4 uWS::WebSocketContext<false, true, carta::PerSocketData>::handleFragment(char
, unsigned long, unsigned int, int, bool, uWS::WebSocketState, void) + 1300 (WebSocketContext.h:93)
9 carta_backend 0x102b16b26 bool uWS::WebSocketProtocol<true, uWS::WebSocketContext<false, true, carta::PerSocketData> >::consumeMessage<6u, unsigned char>(unsigned char, char*&, unsigned int&, uWS::WebSocketState, void) + 758 (WebSocketProtocol.h:328)
10 carta_backend 0x102b16780 uWS::WebSocketProtocol<true, uWS::WebSocketContext<false, true, carta::PerSocketData> >::consume(char*, unsigned int, uWS::WebSocketState, void) + 272 (WebSocketProtocol.h:424)
11 carta_backend 0x102b1661a auto uWS::WebSocketContext<false, true, carta::PerSocketData>::init()::'lambda'(auto*, char*, int)::operator()<us_socket_t>(auto*, char*, int) const + 138 (WebSocketContext.h:286)
12 carta_backend 0x102bc7b05 us_loop_run + 133 (epoll_kqueue.c:147)
13 carta_backend 0x102b13167 uWS::Loop::run() + 8 (Loop.h:159) [inlined]
14 carta_backend 0x102b13167 uWS::run() + 15 (Loop.h:176) [inlined]
15 carta_backend 0x102b13167 uWS::TemplatedApp::run() + 15 (App.h:393) [inlined]
16 carta_backend 0x102b13167 carta::SessionManager::RunApp() + 343 (SessionManager.cc:572)
17 carta_backend 0x102a591d5 main + 3877 (Main.cc:189)
18 dyld 0x1083d052e start + 462

To Reproduce
Steps to reproduce the behavior:

  1. try to use python interface to interact with an existing backend with an incorrect session id (session.interact())
  2. see the carta_backend is still alive
  3. fix the session id to the correct one and re-run the python script
  4. carta_backend will crash

Expected behavior
carta_backend survives in this case

Platform info (please complete the following information):

  • OS [e.g. macOS Monterey]: macOS Monterey
  • Browser [e.g. chrome, safari, electron app]: chrome
  • Browser version [e.g. 22]: 111
  • Backend branch [e.g. dev, v3b2 release]: dev
  • Frontend branch [e.g. dev, v3b2 release]: dev
  • carta-python branch: dev
@kswang1029 kswang1029 added the bug Something isn't working label Mar 17, 2023
@confluence
Copy link
Collaborator

@kswang1029 could you please provide the full test script? I haven't encountered this before (despite frequently correcting bad session IDs); I wonder if it's related to using debug_no_auth.

@kswang1029
Copy link
Contributor Author

@confluence please try the following to see if it works (literally XD)

  1. run a carta_backend (this is a dev build) like
    ./carta_backend --frontend_folder /Users/kswang/carta_build/carta-frontend/build --port 3002 --omp_threads 16 --enable_scripting --no_browser --verbosity 5 --debug_no_auth
  2. run a carta python script like
from carta.session import Session

url_with_token = 'http://localhost:3002'
#session_id = 4201997857 # right
session_id = 4201997856 # wrong
image_file_0 = '/Users/kswang/carta_image_pool/set_HD163296/HD163296_CO_2_1.fits'
img0 = session.open_image(image_file_0)
session.save_rendered_view('test.png')
session.close()

it will fail with the following message

Traceback (most recent call last):
  File "/Users/kswang/carta_pythonInterface_testing/test.py", line 25, in <module>
    img0 = session.open_image(image_file_0)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/validation.py", line 630, in newfunc
    return func(self, *args, **kwargs)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/session.py", line 371, in open_image
    return Image.new(self, path, hdu, False)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/image.py", line 68, in new
    image_id = session.call_action("appendFile" if append else "openFile", directory, file_name, hdu, return_path="frameInfo.fileId")
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/session.py", line 250, in call_action
    return self._protocol.request_scripting_action(self.session_id, path, *args, **kwargs)
  File "/opt/anaconda3/lib/python3.9/site-packages/carta/protocol.py", line 362, in request_scripting_action
    raise CartaRequestFailed(f"{carta_action_description} failed with status {response.status_code}. {backend_message}")
carta.util.CartaRequestFailed: CARTA scripting action .openFile called with parameters ('/Users/kswang/carta_image_pool/set_HD163296', 'HD163296_CO_2_1.fits', '') failed with status 404. No session with ID 4201997856 could be found.
  1. now set the right session_id and rerun the script, we will see the carta_backend crashes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants