Toemsel / Network

C# Network Library

Home Page:https://push-force.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WriteThreadPacketException when sending data async

blockplacer opened this issue · comments

tcpConnection.SendAsync causing WriteThreadPacketException every time it used after few seconds+
causing task cancelled errors on chickenreceiver.
This happens when used with timer etc. when data tried to continuously sent without interrupting.

System.Threading.Tasks.TaskCanceledException
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
 Network.Async.ChickenReceiver.<Send>d__2`1.MoveNext()

System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
Network.Connection.<SendAsync>d__115`1.MoveNext()

  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Dont send big data over packets sending small data should not cause problem

Can you please provide a minimalistic example?

string user_ = new Random().Next(4324, 4823).ToString();
      private async void timer5_Tick(object sender, EventArgs e)
      {
   if (connectionResult == ConnectionResult.Connected)
                      {
                          if (player_ == 9)
                          {
                             
                        myPositionFromServer = await tcpConnection.SendAsync<PositionResponse>(new PositionRequest());//
                                  tcpConnection.Send(new PositionUpdate() { X = stuff__.player.x, Y = stuff__.player.y, Z = stuff__.player.z, user = user_, update_ = update_string });//"update"
                                  update__string = myPositionFromServer.update_;
                                  join_string = myPositionFromServer.update_;
                          }
                      }
}

I not trying to access tcpConnection from other threads. i tried making myPosition global variable due some issues though even changing it to local variable doesnt affects issue

trying to fix error for weeks still i can't find how to fix the problem. beacue writethreadpacketexception isn't explains why it happens. is this exception even about some error in write thread or trying to write from multiple threads(which i not try to write from multiple threads)

I did test your scenario with a timer (1ms tick interval) and my example has no issue.

    Timer timer = new Timer(new TimerCallback(sendStuff));
    timer.Change(0, 2);
    this.connection = (TcpConnection)connection;

    private async void sendStuff(object sender)
        {
            var response = await connection.SendAsync<CalculationResponse>(new CalculationRequest(1, 1));
            Console.WriteLine($"Answer received {response.Result}");
            connection.Send(new CalculationRequest(2, 2));
        }

can you reproduce the issue while working with the examples from the repro?
In order to dig into that issue and to determin why it isn't working in your specific case, I would require more details.

I guess that is that proj. you did post on the Discord as well, but I can't reproduce it there either. Do you have instructions for me to trigger that behaviour?

problem seems to happen after loading map files which they are large+ trying to transmit player coordinates etc.
https://github.com/blockplacer/Server/ i uploaded server files

though that doesnt explain why it even crashes when map isnt loaded.

I tried without loading map. just allowing player fly with clientside objects though its still crashed after few seconds.

problem seems to happen after loading map files which they are large+ trying to transmit player coordinates etc.
https://github.com/blockplacer/Server/ i uploaded server files

There are two server classes, but no client class I could examinate. However, what I see should look good, even thought there is a lot of stuff which you avoid. (Sleeping within a network callback, as an example) I also can't see where you are transmiting data to the client, as you only register chat messages and position updates.

problem seems to happen after loading map files which they are large+ trying to transmit player coordinates etc.
https://github.com/blockplacer/Server/ i uploaded server files

There are two server classes, but no client class I could examinate. However, what I see should look good, even thought there is a lot of stuff which you avoid. (Sleeping within a network callback, as an example) I also can't see where you are transmiting data to the client, as you only register chat messages and position updates.

its rebroadcast method for rebroadcasting player changes in game world as i said earlier game features editable enviroment. thats why i sent it

i going to upload new client now

though that doesnt explain why it even crashes when map isnt loaded.

I tried without loading map. just allowing player fly with clientside objects though its still crashed after few seconds.

I do agree, it shouldn't happen. To narrow the issue down, did you try to send fewer packets? Does that change anything? Try not to update on each Xms, try to update when you have a position change. Something like: newPos != oldPos: sendUpdate();

problem seems to happen after loading map files which they are large+ trying to transmit player coordinates etc.
https://github.com/blockplacer/Server/ i uploaded server files

There are two server classes, but no client class I could examinate. However, what I see should look good, even thought there is a lot of stuff which you avoid. (Sleeping within a network callback, as an example) I also can't see where you are transmiting data to the client, as you only register chat messages and position updates.

its rebroadcast method for rebroadcasting player changes in game world as i said earlier game features editable enviroment. thats why i sent it

i going to upload new client now

zip the whole proj and send it over. That will be a lot faster than digging in the dark.

problem still continues after reverting every change done to program that might break it
heres link to files though i deleted dlls due my slow upload
https://cdn.discordapp.com/attachments/502989127499776009/788087171637837934/game.rar

i might solve the problem if i know whats meaning of WritePacketThreadException
beacuse i tried resetting everything still error appears i tried putting everything in single task, for seeing if this caused by multiple threads. but it didn't worked. i resetted code in shared server stuff what you sent still though error present.

  1. When the Lib can't serialize your packet. Hence, the packet (object) you try to send has invalid (not serializeable) datatypes. Such as external class references.
  2. The remote host isn't available (reachable) anymore. See docs

but weird thing even i replace files with files you sent it still gives errors problem probably caused by host isnt reachable though server code resetted too. i tried just using integers still write packet exception

might be due using player class with some non serializable objects