'What is the accepted approach to diagnose a healthy http call?

I'm tryin to provide a healthy stream of data to a service endpoint, it suppose to get a stream, do its magic and return a transcription. It did for a while, but sporadically and eventually it kept giving me the same exception.

I'm using the SDK the service provider provided with a local azure function in .NET6. I'm testing the requests with POSTMAN. I wrote 2 methods , one for IFormfile that I convert to a stream and one for a URL source that is a stream, but the error is the same:

"Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.."

Their client is based on a HttpClient.

Please, is there a way for me to examine if my code is proper, or if my call is okay? The error began showing up as of last week. I used wireshark to examine the traffic and the only "red" record was from the service provider to my local dev env.Again, keep in mind that all worked, but then this:

THE ERROR:

"Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host" OR: Here is the more detailed error message.. { "statusCode": null, "message": "Error while copying content to a stream.", "data": {}, "innerException": { "ClassName": "System.IO.IOException", "Message": "Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host..", "Data": null, "InnerException": { "ClassName": "System.Net.Sockets.SocketException", "Message": "An existing connection was forcibly closed by the remote host.", "Data": null, "InnerException": null, "HelpURL": null, "StackTraceString": null, "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2147467259, "Source": null, "WatsonBuckets": null, "NativeErrorCode": 10054 }, "HelpURL": null, "StackTraceString": " at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)\r\n at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)\r\n at System.Net.Security.SslStream.g__CompleteWriteAsync|180_1[TIOAdapter](ValueTask writeTask, Byte[] bufferToReturn)\r\n at System.Net.Security.SslStream.WriteAsyncChunked[TIOAdapter](TIOAdapter writeAdapter, ReadOnlyMemory1 buffer)\r\n at System.Net.Security.SslStream.WriteAsyncInternal[TIOAdapter](TIOAdapter writeAdapter, ReadOnlyMemory1 buffer)\r\n at System.Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory`1 source, Boolean async)\r\n at System.Net.Http.HttpContent.g__WaitAsync|56_0(ValueTask copyTask)", "RemoteStackTraceString": null, "RemoteStackIndex": 0, "ExceptionMethod": null, "HResult": -2146232800, "Source": "System.Net.Sockets", "WatsonBuckets": null }, "helpLink": null, "source": "System.Net.Http", "hResult": -2146232800, "stackTrace": " at System.Net.Http.HttpContent.g__WaitAsync|56_0(ValueTask copyTask)\r\n at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stream, Boolean async, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)\r\n at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)\r\n at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)\r\n at Deepgram.Request.ApiRequest.SendHttpRequestAsync(HttpRequestMessage request)\r\n at Deepgram.Request.ApiRequest.SendHttpRequestAsync[T](HttpRequestMessage request)\r\n at Deepgram.Request.ApiRequest.DoStreamRequestAsync[T](HttpMethod method, String uri, CleanCredentials credentials, StreamSource streamSource, Object queryParameters)\r\n at Deepgram.Transcription.PrerecordedTranscriptionClient.GetTranscriptionAsync(StreamSource source, PrerecordedTranscriptionOptions options)\r\n at TranscribeAudioAzureFunction.TranscribeAudio.TranscribeLocalFile(IFormFile audio, String nmsApiKey) in C:\NMS MAIN\AzureSourceControl\nmsRemoteProject\AthensLocal\TranscribeAudioAzureFunction\TranscribeAudioAzureFunction\TranscribeAudio.cs:line 346\r\n at TranscribeAudioAzureFunction.TranscribeAudio.Run(HttpRequest req, ILogger log) in C:\NMS MAIN\AzureSourceControl\nmsRemoteProject\AthensLocal\TranscribeAudioAzureFunction\TranscribeAudioAzureFunction\TranscribeAudio.cs:line 186" }

EXECUTION CODE:

    public static async Task<PrerecordedTranscription> TranscribeUrlFile3(string LinkToUrl, string nmsApiKey)
    {

        var credentials = new Credentials(nmsApiKey);
        var deepgramClient = new DeepgramClient(credentials);

        HttpClient httpClient = new HttpClient();

        using (var s = await httpClient.GetStreamAsync(LinkToUrl))
        {
            using (var fs = new FileStream("tmpAudioUrl", FileMode.CreateNew))
            {
                await s.CopyToAsync(fs);
                fs.Seek(0, SeekOrigin.Begin);

                var response = await deepgramClient.Transcription.Prerecorded.GetTranscriptionAsync(
                new Deepgram.Transcription.StreamSource(
                fs,
                "audio/wav"),
                new Deepgram.Transcription.PrerecordedTranscriptionOptions()
                {
                    Punctuate = true,
                    Utterances = true
                });

                return response;
            }
        }
    }

I apologize in advance if the question is not clear/formulated enough or not according to your standards, but I'm new to this magnificent world of code. Thank you fellow coders.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source