mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jul 2006
Posts: 4,149
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
If I have an udp server "running":
Code:
/sockudp -k pacuserv 8000
and a client "connected" to it:
Code:
/sockudp -kn pacuclient 127.0.0.1 8000 this is a test

If I type /sockclose pacuclient, it triggers on sockclose for the server with $sockerr set to 3:
Code:
on *:sockclose:pacuserv:{
  echo -s SERVER UDP SOCKCLOSE $sockerr -- $sock(pacuserv).wsmsg
}
Quote:
SERVER UDP SOCKCLOSE 3 -- [10054] Connection reset by peer


Is this normal?


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 5,420
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,420
I have a feeling we've been through this one before. Does this post cover the same issue?

That said, I have not been able to reproduce this issue here. I follow the above steps:

1) /sockudp -k pacuserv 8000
2) /sockudp -kn pacuclient 127.0.0.1 8000 this is a test
3) /sockclose pacuclient

And this event did not trigger:

on *:sockclose:pacuserv:{
echo -s SERVER UDP SOCKCLOSE $sockerr -- $sock(pacuserv).wsmsg
}

Last edited by Khaled; 15/01/18 06:42 PM.
Joined: Jul 2006
Posts: 4,149
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
You are right! I remember(ed) this thread you linked to but I thought it was a different issue.
In fact it's the same issue. I assume that if you didn't answer that thread at the end it's because you agree with Saturn that it's correct behavior (although he wasn't so sure himself at the end grin)?

For reference, why this has been bugging me is that, the server use both TCP and UDP, it runs a timer and send udp packet to clients each 45 ms. When clients issue a 'quit', they do so with tcp, but they immediately close the UDP socket, meaning the server will still try to send them packet, until it gets the tcp message.
Of course this is now crystal clear to me, but it wasn't so clear 5 years ago wink
It's a simple fix for my script, I just need to let the udp socket running on client and ignore further packets until the server get the quit on the tcp socket and remove the client from the list of ip/port to send packet to.

That being said, the thread you linked to still had some valid reports I believe so maybe we can use this thread to deal with them:

Quote:
1) "/sockudp -k SERVER" doesn't do anything, I think it should report a syntax error.

2) "/sockudp -kn SERVER" triggers on sockwrite with $sockerr set to 3 with the winsock error message: "[10047] Address family not supported by protocol family", should report a syntax error as well


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
Originally Posted By: Khaled
That said, I have not been able to reproduce this issue here.

Wims left out the core cause of the problem, which is that the server sends a packet to the client. This slightly extended version should be able to reproduce the actual issue:

Code:
alias pacutest {
  ; a server is started
  sockudp -k pacuserv 8000
  ; sometime later, a client sends a request
  sockudp -kn pacuclient 127.0.0.1 8000 This is a request
  ; but for whatever reason, the client socket is closed without waiting for the response
  sockclose pacuclient
}
on *:udpread:pacuserv:{
  ; this response will arrive at the client side after the socket has been closed, prompting an ICMP message
  sockudp -k pacuserv $sock(pacuserv).saddr $sock(pacuserv).sport This is a response
}
on *:sockclose:pacuserv:{
  echo -s SERVER UDP SOCKCLOSE $sockerr -- $sock(pacuserv).wsmsg
  ; the server socket is now gone as a result of getting the ICMP message
  ; thus, one client can make the entire server unavailable, which is highly undesirable
}


See my post in the previous thread for possible solutions..


Saturn, QuakeNet staff
Joined: Jul 2006
Posts: 4,149
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Yeah thanks, I forgot to make it clear in this thread, once I realized it was the same issue, that the server has to send a packet to an IP/PORT combination that is no longer 'valid'.

Quote:
; thus, one client can make the entire server unavailable, which is highly undesirable
This is exactly my problem, I was going to implement the solution I mentioned in my previous post here, but I realized it wouldn't matter much, a malicious user could always close the socket himself with /sockclose and ruin the server, but even a non malicious user could be suffering a blue screen or a power outage or anything that would make the socket close client side.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 5,420
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,420
Thanks, I was able to reproduce the issue. It only reproduced when I closed the socket instantly after sending the data. I have tested two fixes: the first checks for WSAECONNRESET errors on UDP sockets and ignores them. The second applies SIO_UDP_CONNRESET to the socket. Both seem to work. Which do you think would be best in this situation? As mentioned here, with UDP the error is not due to a connection reset but to reachability. So either method sounds like it should work correctly.

Joined: Jul 2006
Posts: 4,149
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,149
Ahhhh, finally! Awesome Khaled!


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
Ah, neat. In that case either fix should suffice indeed. I personally don't see a strong reason for picking one over the other though, and I myself would probably combine both: ignoring WSAECONNRESET for safety reasons, and setting clearing SIO_UDP_CONNRESET for efficiency reasons (but ignoring any failures setting clearing it).

Last edited by Sat; 20/01/18 05:05 PM. Reason: setting -> clearing

Saturn, QuakeNet staff

Link Copied to Clipboard