Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentOutOfRangeException from HandleData method #1

Open
uxiaoyao opened this issue Dec 28, 2022 · 5 comments
Open

ArgumentOutOfRangeException from HandleData method #1

uxiaoyao opened this issue Dec 28, 2022 · 5 comments
Labels
needs further investigation This issue needs further investigation to determine if/any action needs to be taken.

Comments

@uxiaoyao
Copy link

uxiaoyao commented Dec 28, 2022

ArgumentOutOfRangeException: ArgumentOutOfRange_NeedNonNegNum
Parameter name: count
System.ArraySegment`1[T]..ctor (System.Byte[] array, System.Int32 offset, System.Int32 count) (at <c9d3ffd4b98649ee9989e1908eaca019>:0)
Viglucci.UnityRSocket.Transport.TcpDuplexConnection.HandleData (System.Byte[] data) (at Assets/Viglucci/UnityRSocket/Runtime/Transport/TcpDuplexConnection.cs:70)
Viglucci.UnityRSocket.Transport.TcpDuplexConnection.ListenForData () (at Assets/Viglucci/UnityRSocket/Runtime/Transport/TcpDuplexConnection.cs:51)
System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) (at <c9d3ffd4b98649ee9989e1908eaca019>:0)
System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <c9d3ffd4b98649ee9989e1908eaca019>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) (at <c9d3ffd4b98649ee9989e1908eaca019>:0)
System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) (at <c9d3ffd4b98649ee9989e1908eaca019>:0)
System.Threading.ThreadHelper.ThreadStart () (at <c9d3ffd4b98649ee9989e1908eaca019>:0)
UnityEngine.<>c:<RegisterUECatcher>b__0_0(Object, UnhandledExceptionEventArgs)
@viglucci
Copy link
Owner

Hi @uxiaoyao , which version of Unity were you using? Thanks

@uxiaoyao
Copy link
Author

uxiaoyao commented Jan 1, 2023

I'm using 2013.3.13f1c1

@uxiaoyao
Copy link
Author

uxiaoyao commented Jan 1, 2023

Hi @viglucci I just found that the error happened when do a "RequestRepsonse" for a message which is a fire and forget message.

@viglucci
Copy link
Owner

viglucci commented Jan 3, 2023

Thanks for that additional information @uxiaoyao . Can you help me understand better what you mean by the below?

"RequestRepsonse" for a message which is a fire and forget message.

Did you try sending a RequestResponse request to a handler on a server/responder that expected to handle FirstAndForget request and thus didn't return a data portion in the payload?

If this is still an issue for you, it would be helpful if you could provide a reference to a repository that demonstrates the issue or provide relevant code examples from your client and server. Thanks.

@uxiaoyao
Copy link
Author

uxiaoyao commented Jan 7, 2023

Thanks for that additional information @uxiaoyao . Can you help me understand better what you mean by the below?

"RequestRepsonse" for a message which is a fire and forget message.

Did you try sending a RequestResponse request to a handler on a server/responder that expected to handle FirstAndForget request and thus didn't return a data portion in the payload?

If this is still an issue for you, it would be helpful if you could provide a reference to a repository that demonstrates the issue or provide relevant code examples from your client and server. Thanks.

Yes, that's what i mean, my code below:

 void RequestResponse(IMessage message, Action<List<byte>> cb)
        {

            var builder = new CompositeMetadataBuilder();
            builder.Route("account.login.session");

            ICancellable cancellable = _rSocket.RequestResponse(new RSocketPayload { Data = Serialize(message), Metadata = builder.Build() },
                new Subscriber((payload, isComplete) =>
                {
                    string decodedData = Encoding.UTF8.GetString(payload.Data.ToArray());
                    string decodedMetadata = Encoding.UTF8.GetString(payload.Metadata.ToArray());
                    cb.Invoke(payload.Data);
                    /*Debug.Log($"data: {response}");
                    Debug.Log($"metadata: {decodedMetadata}");
                    Debug.Log($"isComplete: {isComplete}");*/
                    if (isComplete)
                    {
                        Debug.Log("RequestResponse done");
                    }
                },
                () =>
                {
                    Debug.Log("RequestResponse done");
                },
                (e) =>
                {
                    cb.Invoke(null);
                    Debug.LogError(e);
                }
            ));
        }

        public IAsyncResult<T> Request<T>(IMessage msg) where T : IMessage<T>
        {
            AsyncResult<T> result = new AsyncResult<T>();

            RequestResponse(msg, (data) =>
            {
                Loom.QueueOnMainThread(() => {
                    var parser = typeof(T).GetProperty("Parser").GetValue(null) as MessageParser<T>;
                    //var parser = typeof(T).GetProperty("Parser") as MessageParser<T>;

                    //var parser = new MessageParser<T>(() => (T)Activator.CreateInstance(typeof(T)));

                    T res = parser.ParseFrom(data.ToArray());
                    result.SetResult(res);

                });

            });
            return result;
        }

        public async void GetSession()
        {
            SessionLoginRequest msg = new();
            msg.SessionId = "";
            var isDone = await this.Request(msg);
            Debug.Log("* SessionLoginRequest:");
            Debug.Log("isDone: " + isDone);
        }

the error happened when i called GetSession method.

@viglucci viglucci added the needs further investigation This issue needs further investigation to determine if/any action needs to be taken. label Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs further investigation This issue needs further investigation to determine if/any action needs to be taken.
Projects
None yet
Development

No branches or pull requests

2 participants