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

System.NullReferenceException In WriteRequest.Release() #57

Closed
lth3726381 opened this issue Sep 10, 2017 · 7 comments
Closed

System.NullReferenceException In WriteRequest.Release() #57

lth3726381 opened this issue Sep 10, 2017 · 7 comments

Comments

@lth3726381
Copy link

lth3726381 commented Sep 10, 2017

NetUV 0.1.125.0
Use NetUV as tcp server ,it happed when read and write lot of "packet".

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=NetUV.Core
StackTrace:

NetUV.Core.dll!NetUV.Core.Common.ThreadLocalPool.Handle.Release<NetUV.Core.Requests.WriteRequest>(NetUV.Core.Requests.WriteRequest value = {NetUV.Core.Requests.WriteRequest}) line 34
NetUV.Core.dll!NetUV.Core.Requests.WriteRequest.Release() line 22
NetUV.Core.dll!NetUV.Core.Requests.WriteBufferRequest.OnWriteCallback(int status = 0) line 78
NetUV.Core.dll!NetUV.Core.Requests.WriteBufferRequest.OnWriteCallback(System.IntPtr handle = {System.IntPtr}, int status = 0) line 85
[native to manage]
[manage to native]
NetUV.Core.dll!NetUV.Core.Native.NativeMethods.RunLoop(System.IntPtr handle = {System.IntPtr}, NetUV.Core.Native.uv_run_mode mode = UV_RUN_DEFAULT) line 109
NetUV.Core.dll!NetUV.Core.Handles.LoopContext.Run(NetUV.Core.Native.uv_run_mode mode = UV_RUN_DEFAULT) line 78
NetUV.Core.dll!NetUV.Core.Handles.Loop.RunDefault() line 32
UvTcpPacketServer.dll!ServerEngine.UvTcpPacketServer<RoomServer.ToClient.ToClientSession>.Start.AnonymousMethod__0() line 26
System.Private.CoreLib.ni.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state)

My loop is running in a standalone thread,and write requests are other thread.

@StormHub
Copy link
Owner

just to clarify, are the write requests submitted from another thread?

@StormHub
Copy link
Owner

or within the loop thread.

@lth3726381
Copy link
Author

write requests are submitted from another thread

@StormHub
Copy link
Owner

That is the reason you get this, you have to submit the writes from the same loop thread;
Here is a simple once off Async handle to send the writes:
bytes[] data = ...;
Async async = loop.CreateAsync(handle =>
{
tcp.QueueWriteStream((byte[])handle.UserToken);
handle.Dispose();
});
async.UserToken = data;
async.Send();

@StormHub
Copy link
Owner

If you want to constantly sending data, you have to run loop in a dedicated thread and post your requests to the loop thread. Again, you can use Async handle to wake up the loop. Similar to
https://github.com/StormHub/NetUV/blob/dev/examples/LoopThread/Program.cs

@lth3726381
Copy link
Author

thanks

@StormHub
Copy link
Owner

Again, please try EventLoop. If you have any issue, please feel free to provide feedback I can improve on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants