# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1618408967 -7200
# Node ID f7275c2c58faccd9d3f85282f708bbd141c6ea8b
# Parent  83822be7704d0f515108d7c89bfa134130f3466e
mod_c2s: Fix traceback if session was destroyed while opening stream (thanks Ge0rG)

Could happen with the 'opportunistic_writes' setting, since then the
stream opening is written directly to the socket, which can in turn
trigger session destruction if the socket somehow got closed just after
the other sent their stream header.

Error happens later when it tries to `hosts[session.host == nil].events`

diff -r 83822be7704d -r f7275c2c58fa plugins/mod_c2s.lua
--- a/plugins/mod_c2s.lua	Wed Apr 14 15:21:13 2021 +0200
+++ b/plugins/mod_c2s.lua	Wed Apr 14 16:02:47 2021 +0200
@@ -92,6 +92,9 @@
 
 	session:open_stream(host, attr.from);
 
+	-- Opening the stream can cause the stream to be closed
+	if session.destroyed then return end
+
 	(session.log or log)("debug", "Sent reply <stream:stream> to client");
 	session.notopen = nil;