Skip to content

Commit 7b014cb

Browse files
committed
xenbus: Fix handling of requests with xsd_sockmsg.len = 0 for socket connections
Following the report at https://lore.kernel.org/xen-devel/CAFLBxZaeTMcF4tcV45MJdCVx4A6qbzQdjKei_Quh_iLrtARVFA@mail.gmail.com/ Without this fix, the backend would be stuck waiting on the zero-sized body until the next request comes in. Instead return the request immediately after reading the header, there's no need to wait for another call to .has_more_input and .input Reported-by: George Dunlap <dunlapg@umich.edu> Signed-off-by: Andrii Sultanov <andriy.sultanov@vates.tech>
1 parent 4a5f925 commit 7b014cb

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

xenbus/xb.ml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@ let can_input con = Queue.can_push con.pkt_out CommandReply
295295

296296
(* NB: can throw Reconnect *)
297297
let input con =
298+
let reset_and_return partial_pkt =
299+
let pkt = Packet.of_partialpkt partial_pkt in
300+
con.partial_in <- init_partial_in () ;
301+
Some pkt
302+
in
298303
if not (can_input con) then
299304
None
300305
else
@@ -309,23 +314,27 @@ let input con =
309314
(* we complete the data *)
310315
if sz > 0 then
311316
Partial.append partial_pkt (Bytes.to_string b) sz ;
312-
if Partial.to_complete partial_pkt = 0 then (
313-
let pkt = Packet.of_partialpkt partial_pkt in
314-
con.partial_in <- init_partial_in () ;
315-
Some pkt
316-
) else
317+
if Partial.to_complete partial_pkt = 0 then
318+
reset_and_return partial_pkt
319+
else
317320
None
318321
| NoHdr (i, buf) ->
319322
(* we complete the partial header *)
320323
if sz > 0 then
321324
Bytes.blit b 0 buf (Partial.header_size () - i) sz ;
322-
con.partial_in <-
323-
( if sz = i then
324-
HaveHdr (Partial.of_string (Bytes.to_string buf))
325-
else
326-
NoHdr (i - sz, buf)
327-
) ;
328-
None
325+
if sz = i then
326+
let partial_pkt = Partial.of_string (Bytes.to_string buf) in
327+
(* If there is no body, we can return the full request immediately *)
328+
if Partial.to_complete partial_pkt = 0 then
329+
reset_and_return partial_pkt
330+
else (
331+
con.partial_in <- HaveHdr partial_pkt ;
332+
None
333+
)
334+
else (
335+
con.partial_in <- NoHdr (i - sz, buf) ;
336+
None
337+
)
329338

330339
let classify t =
331340
match t.Packet.ty with Op.Watchevent -> Watchevent | _ -> CommandReply

0 commit comments

Comments
 (0)