Comparison

plugins/mod_s2s.lua @ 11419:2c26dfc1977f

mod_s2s: Buffer stream error + stream closing tag In "opportunistic writes" mode, prevents ondisconnect from happening while writing the stream closing tag.
author Kim Alvefur <zash@zash.se>
date Wed, 03 Mar 2021 13:34:00 +0100
parent 11417:f84005d06663
child 11525:5f99fcc43938
comparison
equal deleted inserted replaced
11418:f4b76e500768 11419:2c26dfc1977f
501 -- remote_reason: stream error received from the remote server 501 -- remote_reason: stream error received from the remote server
502 -- bounce_reason: stanza error to pass to bounce_sendq because stream- and stanza errors are different 502 -- bounce_reason: stanza error to pass to bounce_sendq because stream- and stanza errors are different
503 local function session_close(session, reason, remote_reason, bounce_reason) 503 local function session_close(session, reason, remote_reason, bounce_reason)
504 local log = session.log or log; 504 local log = session.log or log;
505 if session.conn then 505 if session.conn then
506 local conn = session.conn;
507 conn:pause_writes(); -- until :close
506 if session.notopen then 508 if session.notopen then
507 if session.direction == "incoming" then 509 if session.direction == "incoming" then
508 session:open_stream(session.to_host, session.from_host); 510 session:open_stream(session.to_host, session.from_host);
509 else 511 else
510 session:open_stream(session.from_host, session.to_host); 512 session:open_stream(session.from_host, session.to_host);
538 -- FIXME reason should be managed in a place common to c2s, s2s, bosh, component etc 540 -- FIXME reason should be managed in a place common to c2s, s2s, bosh, component etc
539 local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason; 541 local reason = remote_reason or (reason and (reason.text or reason.condition)) or reason;
540 session.log("info", "%s s2s stream %s->%s closed: %s", session.direction:gsub("^.", string.upper), 542 session.log("info", "%s s2s stream %s->%s closed: %s", session.direction:gsub("^.", string.upper),
541 session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason or "stream closed"); 543 session.from_host or "(unknown host)", session.to_host or "(unknown host)", reason or "stream closed");
542 544
545 conn:resume_writes();
546
543 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote 547 -- Authenticated incoming stream may still be sending us stanzas, so wait for </stream:stream> from remote
544 local conn = session.conn;
545 if reason == nil and not session.notopen and session.direction == "incoming" then 548 if reason == nil and not session.notopen and session.direction == "incoming" then
546 add_task(stream_close_timeout, function () 549 add_task(stream_close_timeout, function ()
547 if not session.destroyed then 550 if not session.destroyed then
548 session.log("warn", "Failed to receive a stream close response, closing connection anyway..."); 551 session.log("warn", "Failed to receive a stream close response, closing connection anyway...");
549 s2s_destroy_session(session, reason, bounce_reason); 552 s2s_destroy_session(session, reason, bounce_reason);