Skip to content

fix: It's best to call SetDeadline before write.#472

Open
mty2015 wants to merge 1 commit into
topfreegames:mainfrom
mty2015:fix-agent
Open

fix: It's best to call SetDeadline before write.#472
mty2015 wants to merge 1 commit into
topfreegames:mainfrom
mty2015:fix-agent

Conversation

@mty2015

@mty2015 mty2015 commented Dec 10, 2025

Copy link
Copy Markdown

When session.Kick is called, it directly calls the Agent.Kick method. However, Agent.Kick does not set a writeTimeout when writing the Kick Packet using the underlying conn. This can cause the method to return an I/O timeout in some scenarios. For example, the code here also sets a timeout parameter, which will affect the write behavior during Kick.

func (a *agentImpl) writeToConnection(ctx context.Context, data []byte) error {
	span := createConnectionSpan(ctx, a.conn, "conn write")

	a.conn.SetWriteDeadline(time.Now().Add(a.writeTimeout))
	_, writeErr := a.conn.Write(data)

	if span != nil {
		defer span.End()

		if writeErr != nil {
			span.RecordError(writeErr)
			span.SetStatus(codes.Error, writeErr.Error())
		}
	}

	return writeErr
}

https://github.com/topfreegames/pitaya/blob/main/pkg/agent/agent.go#L566

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant