From 3ce4dbaa21887f6c315b5ba12835cd92596781d5 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 6 Nov 2026 21:29:01 +0000 Subject: [PATCH 1/5] [lua] Fix error when closing unused socket --- std/lua/_std/sys/net/Socket.hx | 3 ++- std/lua/_std/sys/ssl/Socket.hx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/std/lua/_std/sys/net/Socket.hx b/std/lua/_std/sys/net/Socket.hx index 8aad5951d83..1940a2ec55a 100644 --- a/std/lua/_std/sys/net/Socket.hx +++ b/std/lua/_std/sys/net/Socket.hx @@ -86,7 +86,8 @@ class Socket { } public function close():Void { - _socket.close(); + if (_socket != null) + _socket.close(); } public function read():String { diff --git a/std/lua/_std/sys/ssl/Socket.hx b/std/lua/_std/sys/ssl/Socket.hx index d5fc0196811..78d5f4ec017 100644 --- a/std/lua/_std/sys/ssl/Socket.hx +++ b/std/lua/_std/sys/ssl/Socket.hx @@ -78,7 +78,8 @@ class Socket extends sys.net.Socket { } public override function close():Void { - _sslSocket.close(); + if (_sslSocket != null) + _sslSocket.close(); } } From 9f831ba963cf668326e69a0e5a2be29a5b4dc636 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 6 Nov 2026 21:22:31 +0000 Subject: [PATCH 2/5] [tests] Ensure closing an unused socket is safe --- tests/sys/src/Main.hx | 3 +++ tests/sys/src/net/TestSocket.hx | 10 ++++++++++ tests/sys/src/ssl/TestSocket.hx | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 tests/sys/src/ssl/TestSocket.hx diff --git a/tests/sys/src/Main.hx b/tests/sys/src/Main.hx index 0ee658263e5..09113df294f 100644 --- a/tests/sys/src/Main.hx +++ b/tests/sys/src/Main.hx @@ -17,6 +17,9 @@ class Main { #if false runner.addCase(new net.TestAsyncSocket( #if (hl_ver < version("1.16.0")) false #end )); #end + #if (!jvm && !php) + runner.addCase(new ssl.TestSocket()); + #end var report = Report.create(runner); report.displayHeader = AlwaysShowHeader; report.displaySuccessResults = NeverShowSuccessResults; diff --git a/tests/sys/src/net/TestSocket.hx b/tests/sys/src/net/TestSocket.hx index 97f1f123a0c..fdd05d5bb12 100644 --- a/tests/sys/src/net/TestSocket.hx +++ b/tests/sys/src/net/TestSocket.hx @@ -47,4 +47,14 @@ class TestSocket extends utest.Test { Assert.pass(); } #end + + function testImmediateClose() { + try { + final socket = new Socket(); + socket.close(); + Assert.pass(); + } catch (e) { + Assert.fail('Closing unused socket failed: ${e}'); + } + } } diff --git a/tests/sys/src/ssl/TestSocket.hx b/tests/sys/src/ssl/TestSocket.hx new file mode 100644 index 00000000000..43b4111fd0a --- /dev/null +++ b/tests/sys/src/ssl/TestSocket.hx @@ -0,0 +1,16 @@ +package ssl; + +import sys.ssl.*; +import utest.Assert; + +class TestSocket extends utest.Test { + function testImmediateClose() { + try { + final socket = new Socket(); + socket.close(); + Assert.pass(); + } catch (e) { + Assert.fail('Closing unused socket failed: ${e}'); + } + } +} From 1624feb2156ca9edc275f648284dda7a8453cf40 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 6 Nov 2026 21:27:52 +0000 Subject: [PATCH 3/5] [tests] Remove #if !lua in test using socket close --- tests/unit/src/unit/issues/Issue13031.hx | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/src/unit/issues/Issue13031.hx b/tests/unit/src/unit/issues/Issue13031.hx index 3c8c0aaac94..b23906b5a88 100644 --- a/tests/unit/src/unit/issues/Issue13031.hx +++ b/tests/unit/src/unit/issues/Issue13031.hx @@ -46,9 +46,7 @@ private class RequestSocket extends sys.net.Socket { public override function close() { input = originalInput; output = originalOutput; - #if !lua super.close(); - #end } } #end From 9046d6f0a0b3ab47e8d689551e99b765ff7b5612 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 6 Nov 2026 21:44:01 +0000 Subject: [PATCH 4/5] [tests] Disable ssl socket test on js and python --- tests/sys/src/Main.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/sys/src/Main.hx b/tests/sys/src/Main.hx index 09113df294f..44ef866af48 100644 --- a/tests/sys/src/Main.hx +++ b/tests/sys/src/Main.hx @@ -17,7 +17,7 @@ class Main { #if false runner.addCase(new net.TestAsyncSocket( #if (hl_ver < version("1.16.0")) false #end )); #end - #if (!jvm && !php) + #if (!jvm && !php && !js && !python) runner.addCase(new ssl.TestSocket()); #end var report = Report.create(runner); From a3957d199aa7a0d2cb14022ca4d8864eda207b1a Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Sat, 7 Nov 2026 17:14:32 +0000 Subject: [PATCH 5/5] [lua] Make socket fields nullable --- std/lua/_std/sys/net/Socket.hx | 2 +- std/lua/_std/sys/ssl/Socket.hx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/std/lua/_std/sys/net/Socket.hx b/std/lua/_std/sys/net/Socket.hx index 1940a2ec55a..d4fba431430 100644 --- a/std/lua/_std/sys/net/Socket.hx +++ b/std/lua/_std/sys/net/Socket.hx @@ -68,7 +68,7 @@ class Socket { var custom:Dynamic; - var _socket:LuaSocket; + var _socket:Null; var blocking = false; var timeout = null; diff --git a/std/lua/_std/sys/ssl/Socket.hx b/std/lua/_std/sys/ssl/Socket.hx index 78d5f4ec017..f9e897406af 100644 --- a/std/lua/_std/sys/ssl/Socket.hx +++ b/std/lua/_std/sys/ssl/Socket.hx @@ -48,7 +48,7 @@ import haxe.io.Error; @:coreApi(check = Off) class Socket extends sys.net.Socket { - var _sslSocket:SslTcpClient; + var _sslSocket:Null; private function wrap(sock:LuaSocket):SslTcpClient { var res = LuaSecSsl.wrap(sock, {mode: Client, protocol: Any});