Skip to content

Commit 4e2d23f

Browse files
committed
Improve TLS server error messages when incoming connection fails
1 parent 003aa6c commit 4e2d23f

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/SecureServer.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ function ($conn) use ($that) {
184184
$that->emit('connection', array($conn));
185185
},
186186
function ($error) use ($that, $connection) {
187+
$error = new \RuntimeException(
188+
'Connection from ' . $connection->getRemoteAddress() . ' failed during TLS handshake: ' . $error->getMessage(),
189+
$error->getCode(),
190+
$error
191+
);
192+
187193
$that->emit('error', array($error));
188194
$connection->end();
189195
}

tests/FunctionalSecureServerTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,10 @@ public function testEmitsErrorIfConnectionIsClosedBeforeHandshake()
420420

421421
$error = Block\await($errorEvent, $loop, self::TIMEOUT);
422422

423+
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshak
423424
$this->assertTrue($error instanceof \RuntimeException);
424-
$this->assertEquals('Connection lost during TLS handshake', $error->getMessage());
425+
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
426+
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
425427
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
426428
}
427429

@@ -445,8 +447,10 @@ public function testEmitsErrorIfConnectionIsClosedWithIncompleteHandshake()
445447

446448
$error = Block\await($errorEvent, $loop, self::TIMEOUT);
447449

450+
// Connection from tcp://127.0.0.1:39528 failed during TLS handshake: Connection lost during TLS handshak
448451
$this->assertTrue($error instanceof \RuntimeException);
449-
$this->assertEquals('Connection lost during TLS handshake', $error->getMessage());
452+
$this->assertStringStartsWith('Connection from tcp://', $error->getMessage());
453+
$this->assertStringEndsWith('failed during TLS handshake: Connection lost during TLS handshake', $error->getMessage());
450454
$this->assertEquals(defined('SOCKET_ECONNRESET') ? SOCKET_ECONNRESET : 0, $error->getCode());
451455
}
452456

0 commit comments

Comments
 (0)