File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -175,14 +175,19 @@ protected virtual void Dispose(bool disposing)
175175 // and unmanaged resources.
176176 if ( disposing )
177177 {
178- if ( this . Connection . State == Internal . ConnectState . Connected )
178+ if ( this . Connection ? . State == Internal . ConnectState . Connected )
179179 {
180180 Logger . Trace ( "HiveMQClient Dispose: Disconnecting connected client." ) ;
181181 try
182182 {
183183 // Use Task.Run to handle the async disconnect without blocking
184+ // Use a reasonable timeout to avoid hanging indefinitely
184185#pragma warning disable VSTHRD002 // Synchronous Wait in dispose pattern is intentional to ensure cleanup
185- Task . Run ( async ( ) => await this . DisconnectAsync ( ) . ConfigureAwait ( false ) ) . Wait ( 5000 ) ;
186+ var disconnectTask = Task . Run ( async ( ) => await this . DisconnectAsync ( ) . ConfigureAwait ( false ) ) ;
187+ if ( ! disconnectTask . Wait ( 5000 ) )
188+ {
189+ Logger . Warn ( "Disconnect operation timed out during dispose" ) ;
190+ }
186191#pragma warning restore VSTHRD002
187192 }
188193 catch ( Exception ex )
You can’t perform that action at this time.
0 commit comments