--- lang: ja-jp breaks: true --- # SignalR .NET クライアントから Hub に接続しようとするとエラーとなる。 2021-09-08 ## コンソールのログ #### サーバ側 ※ `net6.0` ```shell= dbug: Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionManager[1] New connection cfh_HBMbGbqP4rfcANO3yw created. dbug: Microsoft.AspNetCore.Http.Connections.Internal.HttpConnectionDispatcher[10] Sending negotiation response. ``` #### クライアント側 ※コンソールアプリケーション `net6.0` ```shell= dbug: Microsoft.AspNetCore.SignalR.Client.HubConnection[40] Registering handler for client method 'ReceiveMessage'. dbug: Microsoft.AspNetCore.SignalR.Client.HubConnection[41] Starting HubConnection. dbug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[1] Starting HttpConnection. dbug: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[8] Establishing connection with server at 'http://localhost:5000/ServiceHub_V2'. fail: Microsoft.AspNetCore.Http.Connections.Client.HttpConnection[10] Failed to start connection. Error getting negotiation response from 'http://localhost:5000/ServiceHub_V2'. System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: スレッドの終了またはアプリケーションの要求によって、I/O 処理は中止されました。. ---> System.Net.Sockets.SocketException (995): スレッドの終了またはアプリケーションの要求によって、I/O 処理は中止されました。 --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token) at System.Net.Http.HttpConnection.FillAsync(Boolean async) at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean async, Boolean foldedHeadersAllowed) at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Connections.Client.Internal.AccessTokenHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Connections.Client.Internal.LoggingHttpMessageHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.SendAsyncCore(HttpRequestMessage request, HttpCompletionOption completionOption, Boolean async, Boolean emitTelemetryStartStop, CancellationToken cancellationToken) at Microsoft.AspNetCore.Http.Connections.Client.HttpConnection.NegotiateAsync(Uri url, HttpClient httpClient, ILogger logger, CancellationToken cancellationToken) ``` ## 単純に私のバグでした 単純に `await` `Task` の記述漏れにより、`connection.StartAsync()` が非同期実行されてました。。。 ###### tags: `SignalR` `Hub` `await` `Task`