Skip to content

[BUG] AsyncUdpConnection 连接失败时调用 close 报错 #1123

@ttlxihuan

Description

@ttlxihuan

AsyncUdpConnection 连接失败时调用 close 报错,如果拦截报错就可能导致回调引用不能释放。

Error: Call to a member function offReadable() on null in vendor\workerman\workerman\src\Connection\AsyncUdpConnection.php:134

兼容示例代码:
`
public function close(mixed $data = null, bool $raw = false): void
{
if ($data !== null) {
$this->send($data, $raw);
}
if($this->connected){
try {
$this->connected = false;
$this->eventLoop->offReadable($this->socket);
fclose($this->socket);
} catch (Throwable) {
}
}
// Try to emit onClose callback.
if ($this->onClose) {
try {
($this->onClose)($this);
} catch (Throwable $e) {
$this->error($e);
}
}
$this->onConnect = $this->onMessage = $this->onClose = $this->eventLoop = $this->errorHandler = null;
}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions