onnxruntime
2b8176cf - Fix WebGPU EP crash on exit (#27569)

Commit
5 days ago
Fix WebGPU EP crash on exit (#27569) ### Description Fixes multiple issues that related to crash and memory leak. 1. Fix an uncommon situation that `BucketCacheManager` may hold pending buffers while cleaning up the WebGPU context, which causes memory leak. 2. Change the WebGPU default instance from a RAII wrapper (wgpu::Instance) to a raw pointer (WGPUInstance) so that it will not be destructed automatically at process exit, which may cause a crash due to accessing DXC code while dxcompiler.dll already unloaded. 3. Fix a crash in a situation that the default ORT logger destructed before a WebGPU device, so that the device callbacks are guarded by condition `logging::LoggingManager::HasDefaultLogger()`. Also includes a few fixes related to Node.js binding. 1. the `OrtEnv` was used as a function local variable. This is problematic because the destruction of OrtEnv may be too late, where some DLLs are already unloaded. (The order of DLL unloading at process exit is not totally controllable). Change it to: - if OrtEnv is constructed on main thread, a cleanup hook will be registered when Node.js starts to exit. If the callback is not called (eg. uncaught exception is thrown), the OrtEnv will not be released. - if OrtEnv is constructed on worker thread, just leave it and allow it to leak at exit. 2. because of (1), if OrtEnv is released already, do not release any active sessions (they are object wraps that destructed later than registered hooks). All of the changes above should have covered different scenarios but ensures: - if any resource is intentionally leaked, it must be at process exit. - if it's not at process exit, resources lifecycle should be managed correctly. - best efforts (but not guarantee) to release resources safely, as to be friendly to the memory leak detector. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Author
Parents
Loading