[Libwebsockets] close changes between 2.2 and 2.3 stable

Mario Theodoridis mario.theodoridis at regify.com
Thu Aug 24 16:22:26 CEST 2017


On 24/08/17 15:44, Andy Green wrote:
>
> The main difference is this:
>
> https://github.com/warmcat/libwebsockets/commit/3b0066cb3fec6baee98a3dcb2cecf11463453ed5 
>
>
> Basically before that patch, we just always dumbly try to send the 
> close packet when the we try to close the connection.  That doesn't 
> take into account the connection state; but if we couldn't send it or 
> the close packet sequence was bad the connection would anyway close.
>
> After the patch the close packet observes the same "wait until 
> writable" rules as any other write.  A timeout will just close it if 
> it takes too long to get a chance to write it.
>
> This became necessary because with lws-meta protocol, there is a 
> parent wsi that actually has the tcp connection, and multiple child 
> wsi that multiplex their different protocol traffic on the same parent 
> connection.  In the case a child is closing, he can't just randomly 
> dump his close packet on the tcp connection without taking care of the 
> parent mux state.  Since the child will only hear he can write when 
> the parent mux state is good for it, the patch takes care of that 
> problem.

Ok, i understand.

> The relevant changes are in the patch above, assuming that's related 
> to it.

I saw that, but didn't grok it.

> Can you tell what the client thinks happened, in terms of if it 
> received the close packet from the server?

Here's a packet dump starting with the request that triggered the close

No.     Time           Source Destination           Protocol Length Info
      12 0.039986000    127.0.0.1 127.0.0.1             WebSocket 300    
WebSocket Text [FIN] [MASKED]

Frame 12: 300 bytes on wire (2400 bits), 300 bytes captured (2400 bits) 
on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 
00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 
(127.0.0.1)
Transmission Control Protocol, Src Port: 42339 (42339), Dst Port: 17681 
(17681), Seq: 216, Ack: 176, Len: 234
[2 Reassembled TCP Segments (242 bytes): #10(8), #12(234)]
WebSocket
     1... .... = Fin: True
     .000 .... = Reserved: 0x00
     .... 0001 = Opcode: Text (1)
     1... .... = Mask: True
     .111 1110 = Payload length: 126 Extended Payload Length (16 bits)
     Extended Payload length (16 bits): 234
     Masking-Key: e1aa702a
     Payload
         Text: 9a881f5ac390525994c8034993c3124fc38652488ed21559...
     Unmask Payload
         [Text unmask [truncated]: 
{"op":"subscribe","boxes":[{"uid":"abc4567890123456789012345678901234567890","boxId":1,"email":"u1 at test.com","accessCode":"rc10"},{"uid":"def4567890123456789012345678901234567890","boxId":2,"email":"u1 at test.com","a]

No.     Time           Source Destination           Protocol Length Info
      13 0.039992000    127.0.0.1 127.0.0.1             TCP      66     
17681→42339 [ACK] Seq=176 Ack=450 Win=45952 Len=0 TSval=1037189488 
TSecr=1037189488

Frame 13: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on 
interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 
00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 
(127.0.0.1)
Transmission Control Protocol, Src Port: 17681 (17681), Dst Port: 42339 
(42339), Seq: 176, Ack: 450, Len: 0

No.     Time           Source Destination           Protocol Length Info
      14 1.555924000    127.0.0.1 127.0.0.1             TCP      66     
17681→42339 [FIN, ACK] Seq=176 Ack=450 Win=45952 Len=0 TSval=1037189867 
TSecr=1037189488

Frame 14: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on 
interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 
00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 
(127.0.0.1)
Transmission Control Protocol, Src Port: 17681 (17681), Dst Port: 42339 
(42339), Seq: 176, Ack: 450, Len: 0

No.     Time           Source Destination           Protocol Length Info
      15 1.566068000    127.0.0.1 127.0.0.1             TCP      66     
42339→17681 [FIN, ACK] Seq=450 Ack=177 Win=44800 Len=0 TSval=1037189869 
TSecr=1037189867

Frame 15: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on 
interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 
00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 
(127.0.0.1)
Transmission Control Protocol, Src Port: 42339 (42339), Dst Port: 17681 
(17681), Seq: 450, Ack: 177, Len: 0

No.     Time           Source Destination           Protocol Length Info
      16 1.566083000    127.0.0.1 127.0.0.1             TCP      66     
17681→42339 [ACK] Seq=177 Ack=451 Win=45952 Len=0 TSval=1037189869 
TSecr=1037189869

Frame 16: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on 
interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 
00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 
(127.0.0.1)
Transmission Control Protocol, Src Port: 17681 (17681), Dst Port: 42339 
(42339), Seq: 177, Ack: 451, Len: 0


-- 
Mit Freundlichen Grüßen / Regards

Mario Theodoridis

regify GmbH
Römerstrasse 39 | D-78183 Hüfingen
Amtsgericht Freiburg HRB 709343
Telefon: +49 771 8978 4238




More information about the Libwebsockets mailing list