aws / aws-sdk-net

The official AWS SDK for .NET. For more information on the AWS SDK for .NET, see our web site:
http://aws.amazon.com/sdkfornet/
Apache License 2.0
2.05k stars 853 forks source link

[Unity] [Android] I got Exception when sending data to Kinesis Stream on Android #2501

Open GearThuanDV opened 1 year ago

GearThuanDV commented 1 year ago

Describe the bug

I am using AWSSDK in unity to send data from my game to Kinesis Stream. My credential is CognitoAWSCredentials

After I finish my implementation, I can send events to Kinesis Stream on Unity Editor. But on Android, it does not work. I got this exception on Android:

System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error getting response stream (ReadDone2): ReceiveFailure ---> System.Exception: at System.Net.WebConnection.HandleError (System.Net.WebExceptionStatus st, System.Exception e, System.String where) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0 at System.AsyncCallback.Invoke (System.IAsyncResult ar) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0 at System.Action.Invoke () <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0 at System.Threading.ContextCallback.Invoke (System.Object state) <0x00000 + 0xffffffff> 0 in <00000000000000000000000000000000>:0 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback,

Please help me to check this bug

Expected Behavior

Android can send events normally without exception

Current Behavior

The exception is thrown on Android devices when sending data to the Kinesis Stream

Reproduction Steps

Possible Solution

No response

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

aws-sdk-dotnet-core/3.3.107.22

Targeted .NET Platform

.Net Standard 2.0

Operating System and version

Android

ashishdhingra commented 1 year ago

Hi @GearThuanDV,

Good morning.

Thanks for reporting the issue. Could you please the following:

Thanks, Ashish

GearThuanDV commented 1 year ago

Thank you for your reply @ashishdhingra, I added this code:

Amazon.AWSConfigs.LoggingConfig.LogResponses = Amazon.ResponseLoggingOption.Always;
Amazon.AWSConfigs.LoggingConfig.LogTo = Amazon.LoggingOptions.SystemDiagnostics;
Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener());

but Amazon.AWSConfigs.AddTraceListener("Amazon", new System.Diagnostics.ConsoleTraceListener()); does not work on unity

After updating the AWSConfigs, this is the new exception message on Android:

 System.AggregateException: One or more errors occurred. (The server returned an invalid or unrecognized response.) ---> System.IO.IOException: The server returned an invalid or unrecognized response.
  at System.Net.Http.HttpConnection.FillAsync () [0x0016e] in <066d0bcaf3054ea99595013bff4ba65c>:0 
  at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync (System.Boolean foldedHeadersAllowed) [0x002a0] in <066d0bcaf3054ea99595013bff4ba65c>:0 
  at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync (System.Threading.CancellationToken cancellationToken) [0x00124] in <2388fb2f52874f24a06c26385b243d66>:0 
  at Amazon.Runtime.Internal.HttpHandler`1[TRequestContent].InvokeAsync[T] (Amazon.Runtime.IExecutionContext executionContext) [0x0024b] in <2388fb2f52874f24a06c26385b243d66>:0 
  at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T] (Amazon.Runtime.IExecutionContext executionContext) [0x0007c] in <2388fb2f52874f24a06c26385b243d66>:0 
  at Amazon.Runtime.Internal.ErrorHandler.In

This bug also happens with the latest version on NuGet:

my code snippet:

 void OnSendSingleRecord() {
        logText.text = "sendingSingle";
        using (var memoryStream = new MemoryStream())
        using (var streamWriter = new StreamWriter(memoryStream))
        {
            streamWriter.Write(message_to_send1);
            var task = awsClient.PutRecordAsync(new PutRecordRequest
                {
                    Data = memoryStream,
                    PartitionKey = kinesis_stream_partition_key,
                    StreamName = delivery_stream_name
                }
            );

            task.ContinueWith(
                _ => {
                    if (_.Exception == null) {
                        Debug.LogError("===Single Success");
                        logText.text = "===Single Success";
                    } else {
                        Debug.LogError($"===Single Failed \n {_.Exception}");
                        logText.text = $"===Single Failed \n {_.Exception}";
                    }
                });
        }
    }