Skip to content

SMB/NFS: shut the connection pools down after the core is unloaded - #19931

Closed
WizzardSK wants to merge 1 commit into
libretro:masterfrom
WizzardSK:smb-shutdown-after-core
Closed

WizzardSK wants to merge 1 commit into
libretro:masterfrom
WizzardSK:smb-shutdown-after-core

Conversation

@WizzardSK

Copy link
Copy Markdown
Contributor

On quit, retroarch_main_quit_finish() freed the SMB and NFS connection pools before main_exit() deinitialised the core. A core that closes files it has open on a share when it unloads then closed them on a freed connection and RetroArch crashed on the way out.

Seen with the Vita3K core on Android, which reads its games through FILE* streams over the VFS (fopencookie) and closes them in its deinit:

signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xffffffff8000007c
  #00 libretroarch-activity.so (retro_vfs_file_close_smb+64)
  #01 libretroarch-activity.so (retro_vfs_file_close_impl+44)
  #02 vita3k_libretro_android.so
  #03 libc.so (__FILE_close(__sFILE*)+248)
  ...
  #09 libretroarch-activity.so (runloop_event_deinit_core+500)
  #11 libretroarch-activity.so (retroarch_main_deinit_finish+16)
  #12 libretroarch-activity.so (main_exit+376)

The shutdown now runs in main_exit() right after RARCH_CTL_MAIN_DEINIT, when no core is left to use the pools. Closing content without quitting is unchanged: the pools stayed up then before as well.

retroarch_main_quit_finish() freed the SMB and NFS pools before
main_exit() deinitialised the core, so a core that closes files it has
open on a share in its unload or deinit (Vita3K, through FILE* streams
over the VFS) closed them on a freed connection: SIGSEGV in
retro_vfs_file_close_smb() on quit.
@LibretroAdmin

Copy link
Copy Markdown
Contributor

Thanks! Merged into master with your authorship kept.

I added a small follow-up on top: smb_shutdown() and nfs_shutdown() now unhook the pool first and only free it when no connection is still in use. Two things can still hold one at that point: an SMB file nobody closed (an open SMB stream keeps its slot for its whole lifetime), and a background task the exit's 3-second drain left stuck on a dead share. Either would have hit the same freed-connection crash. If something is still holding the pool it's left alone, since the process is exiting anyway. The shutdown stays where you put it, before frontend_driver_deinit(), because the Switch tears its sockets down there.

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.

2 participants