Backend Development 3 min read

v0.0.7 Update: Adding Keepalive Timeout to TCP RPC Server

Version v0.0.7 introduces a configurable keepalive timeout for the TCP RPC server, automatically closing idle client connections after a set period, reducing resource usage and preventing memory leaks while allowing the client to transparently reconnect when needed.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
v0.0.7 Update: Adding Keepalive Timeout to TCP RPC Server

Version v0.0.7 builds on v0.0.6 by introducing a keepalive timeout setting for the TCP RPC server, allowing the server to automatically close idle client connections after a configurable period, thereby reducing performance overhead, saving resources, and preventing memory leaks.

When the server closes a client connection, subsequent calls from the client’s call() method will trigger an automatic reconnection, which is transparent to the user, so developers do not need to handle the closed‑connection case manually.

The default keepalive timeout is set to 75 seconds, matching Nginx’s default, but it can be customized via the setKeepaliveTimeout() method as shown in the example below.

from agileutil.rpc.server import TcpRpcServer

def sayHello(name):
    return 'hello ' + name

s = TcpRpcServer('0.0.0.0', 9988)
s.setKeepaliveTimeout(10)  # server will close idle connections after 10 seconds
s.regist(sayHello)
s.serve()

Client usage example demonstrates creating a TcpRpcClient , making a call, sleeping longer than the timeout, and then calling again, which causes the client to automatically reconnect.

from agileutil.rpc.client import TcpRpcClient
import time

cli = TcpRpcClient('127.0.0.1', 9988, timeout = 2)
resp = cli.call(func = 'sayHello', args=('zhangsan',))
print('resp', resp)
time.sleep(15)
resp = cli.call(func = 'sayHello', args=('zhangsan',))  # client will auto‑reconnect
print('resp', resp)
backendPythonRPCTCPServerkeepalive
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.