跳到正文
Terraria Forum· Innocenco·· 8 小时前AI 评分31

[多人模式] 《泰拉瑞亚》专用服务器在打开TCP连接未完成握手时崩溃并抛出未处理 ObjectDisposedException

[Multiplayer] Dedicated server crashes with unhandled ObjectDisposedException when a TCP connection is opened without completing the handshake

AI 导读

《泰拉瑞亚》1.4.5.7原版专用服务器在第二次收到未完成TCP握手的连接时崩溃,抛出未处理 ObjectDisposedException。该问题在端口7777复现,首次连接不崩溃而第二次约30毫秒后触发,TCP健康检查或端口扫描均可引起。正常玩家联机不受影响,世界文件保存无损坏,但进程退出码0易被容器运行时误判为干净关闭。

正文

Vanilla dedicated server, no mods, no TShock. Official Linux binaries from
terraria.org (terraria-server-1457.zip), running in a Docker container on
Ubuntu 24.04 LTS.

DESCRIPTION

The dedicated server terminates with a FATAL UNHANDLED EXCEPTION when a TCP
connection is opened to the game port and closed again without completing the
Terraria handshake. This is exactly what any TCP health check, uptime monitor,
or port scanner does.

The crash does not happen on the first such connection. It happens on the
second one, roughly 30 ms after it arrives. This suggests the first connection
leaves a disposed socket in the client list, and the next pass of
Netplay.UpdateConnectedClients() then accesses it.

Regular players are not affected. Joining and leaving works cleanly.

STEPS TO REPRODUCE

1. Start a vanilla 1.4.5.7 dedicated server.
2. Open a TCP connection to port 7777 and close it immediately without sending
any Terraria protocol data (e.g. nc -z <host> 7777).
3. Repeat once.
4. The server crashes on the second connection.

In my case the trigger was an Uptime Kuma TCP monitor polling every 60 seconds.
The server crashed every 120 seconds - on every second poll - for hours.

EVIDENCE

Blocking the port with a firewall rule stopped the crashes entirely:

- Port reachable: 32 crashes in ~100 minutes
- Port blocked (iptables DROP): 0 crashes in 11 minutes, 0 connections logged
- Port reachable again, monitor interval raised to 30 minutes: stable

LOG (UTC timestamps)

2026-08-20T21:49:15.308Z Terraria Server v1.4.5.7
2026-08-20T21:49:15.308Z Listening on port 7777
2026-08-20T21:49:16.384Z Server started
2026-08-20T21:49:54.465Z 172.28.0.1:36240 is connecting... <- first, no crash
2026-08-20T21:50:54.468Z 172.28.0.1:59432 is connecting... <- second
2026-08-20T21:50:54.496Z ================
2026-08-20T21:50:54.496Z 08/20/2026 21:50:54: Unhandled Exception
2026-08-20T21:50:54.496Z Thread: 8 [Server Loop Thread]
2026-08-20T21:50:54.496Z Culture:
2026-08-20T21:50:54.496Z Exception: System.ObjectDisposedException: Cannot access a disposed object.
2026-08-20T21:50:54.496Z Object name: 'System.Net.Sockets.NetworkStream'.
2026-08-20T21:50:54.496Z at System.Net.Sockets.NetworkStream.get_DataAvailable ()
2026-08-20T21:50:54.496Z at Terraria.Net.Sockets.DebugNetworkStream.get_HasBufferedData ()
2026-08-20T21:50:54.496Z at Terraria.Net.Sockets.TcpSocket.Terraria.Net.Sockets.ISocket.IsConnected ()
2026-08-20T21:50:54.496Z at Terraria.RemoteClient.IsConnected ()
2026-08-20T21:50:54.496Z at Terraria.Netplay.UpdateConnectedClients ()
2026-08-20T21:50:54.496Z at Terraria.Netplay.ServerLoop ()
2026-08-20T21:50:54.496Z at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state)
2026-08-20T21:50:54.496Z at System.Threading.ExecutionContext.RunInternal (...)
2026-08-20T21:50:54.496Z at System.Threading.ExecutionContext.Run (...)
2026-08-20T21:50:54.496Z at System.Threading.ThreadHelper.ThreadStart ()
2026-08-20T21:50:54.496Z HResult: -2146232798
2026-08-20T21:50:54.497Z [ERROR] FATAL UNHANDLED EXCEPTION: (identical stack trace)

The world file itself is never damaged - the server saves cleanly and the
.bak rotation works as expected.

ADDITIONAL NOTES

- The exception is not caught anywhere in ServerLoop, so it takes the whole
process down. The process exits with code 0, which makes it look like a
clean shutdown to any supervisor or container runtime.
- Terraria.Net.Sockets.DebugNetworkStream appearing in a release build may be
worth a look on its own.
- I cannot say with certainty whether 1.4.5.6 is affected. My server ran
1.4.5.6 for weeks with the same 60-second monitor and no visible restart
loop, but it was running under a wrapper script that may have masked the
crashes. I did once have that server hang with the port still in LISTEN,
~114% CPU and no further log output - possibly the same issue presenting
differently. Treat this as a suspicion, not a confirmed regression.
- Any publicly reachable server on the default port 7777 will hit this
regularly through internet-wide port scanning, not just through monitoring.

来源:Terraria Forum · forums.terraria.org