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

Slicer-4.13 hangs at startup on Windows11 #5945

Closed
lassoan opened this issue Oct 12, 2021 · 2 comments · Fixed by #5947
Closed

Slicer-4.13 hangs at startup on Windows11 #5945

lassoan opened this issue Oct 12, 2021 · 2 comments · Fixed by #5947
Assignees
Labels
Type: Bug Something isn't working correctly
Milestone

Comments

@lassoan
Copy link
Contributor

lassoan commented Oct 12, 2021

Slicer does not start up (hangs, then the operating system terminates it) on Windows11

See discussion here:
https://discourse.slicer.org/t/slicer-on-windows-11/20085/11

Environment

  • Slicer version: Slicer 4.13.0-2021-10-08
  • Operating system: Windows 11 Pro, Version: 21H2, OS build: 22000.194
@lassoan lassoan added the Type: Bug Something isn't working correctly label Oct 12, 2021
@lassoan lassoan added this to the Slicer 4.13.0 milestone Oct 12, 2021
@lassoan lassoan self-assigned this Oct 12, 2021
@lassoan
Copy link
Contributor Author

lassoan commented Oct 12, 2021

I did some more debugging and I can confirm what @jamesobutler found above that the application's main thread hangs in the Windows kernel when running the _fsstat64() function. This function is called by openblas (libopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll) that numpy loads when the application is starting up.

The hanging function call can be reproduced in Python:

import _ctypes
_ctypes.LoadLibrary(r"C:\D\S4RD\python-install\Lib\site-packages\numpy\.libs\libopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll", 0)

and in C++

LoadLibraryExA("C:\\D\\S4RD\\python-install\\Lib\\site-packages\\numpy\\.libs\\libopenblas.WCDJNK7YVMPZQ2ME2ZZHJJRJ3JIKNDB7.gfortran-win_amd64.dll", NULL, 0);

Most likely this library attempts to read from stdin and it gets blocked (on Windows, reading from a pipe is a blocking operation).

As I suspected, this is related to standard input/output/error redirection. If we don't redirect the stdout and stderr to the logs then the problem does not occur. For example, if we comment out this->ErrorLogModel->registerMsgHandler(new ctkErrorLogFDMessageHandler); in qSlicerApplicationPrivate::init() then the application starts normally. But of course this is not a good solution because we want to capture outputs.

It is interesting to note that the hang seems to depend on timing. For example, by just adding a breakpoint in the logging setup code in a RelWithDebInfo build makes the problem go away (even if the breakpoint is not hit). However, simply adding a this->processEvents() or Sleep(1000) function call in the main thread right after calling q->setupFileLogging(); does not fix the issue.

Since this issue only occurs with this particular DLL, and only if it is loaded after output redirections are set up (anytime after q->setupFileLogging(); call in qSlicerApplicationPrivate::init()), an easy temporary workaround is to import numpy before file logging is set up. For example in S4\Base\Python\slicer\__init__.py. This solves the problem because import numpy loads the openblas DLL into the process, so next time the DLL loading is requested then the operating system just uses the DLL already in the memory.

lassoan added a commit to lassoan/Slicer that referenced this issue Oct 12, 2021
numpy has to be loaded early to avoid hang when loading openblas library.
This is a temporary workaround and may be removed if the related issue is fixed in Windows11 or numpy (or we find a nicer solution in Slicer).

fixes Slicer#5945
pieper pushed a commit that referenced this issue Oct 12, 2021
numpy has to be loaded early to avoid hang when loading openblas library.
This is a temporary workaround and may be removed if the related issue is fixed in Windows11 or numpy (or we find a nicer solution in Slicer).

fixes #5945
@jamesobutler
Copy link
Contributor

I'm glad that the libopenblas information was a helpful hint. Thanks for tracking down a workaround! I'll keep an eye on Windows 11 compatibility issues and if this workaround becomes no longer needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working correctly
Development

Successfully merging a pull request may close this issue.

2 participants