Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithReadTimeout 不起作用的原因是什么 #174

Open
Yajun312890225 opened this issue Jul 5, 2022 · 10 comments
Open

WithReadTimeout 不起作用的原因是什么 #174

Yajun312890225 opened this issue Jul 5, 2022 · 10 comments
Labels
question Further information is requested

Comments

@Yajun312890225
Copy link

使用事例代码,WithReadTimeout 设置了时间,但是不会触发超时操作,还有请问如何超时断掉连接WithIdleTimeout也不起作用
Go版本1.18.1

@Hchenn
Copy link
Contributor

Hchenn commented Jul 5, 2022

这里没 bug 哈,在 OnRequest 里进行 read,没数据会超时。
能否贴下核心代码,一起看看原因呢?

@Hchenn Hchenn added the question Further information is requested label Jul 5, 2022
@Yajun312890225
Copy link
Author

Yajun312890225 commented Jul 5, 2022

func handle(ctx context.Context, connection netpoll.Connection) error {

reader := connection.Reader()
defer reader.Release()
msg, err := reader.ReadBinary(reader.Len())
if err != nil {
	fmt.Println(err)
	return err
}
fmt.Println(string(msg))
return nil

}

这里会一直等待,不会触发超时

@Hchenn
Copy link
Contributor

Hchenn commented Jul 5, 2022

func handle(ctx context.Context, connection netpoll.Connection) error {

reader := connection.Reader()
defer reader.Release()
msg, err := reader.ReadBinary(reader.Len())
if err != nil {
	fmt.Println(err)
	return err
}
fmt.Println(string(msg))
return nil

}

这里会一直等待,不会触发超时

handle 是 回调 !对端没数据,根本就不会调。

@Yajun312890225
Copy link
Author

func句柄(ctx context.Context,连接netpoll.Connection)错误{

reader := connection.Reader()
defer reader.Release()
msg, err := reader.ReadBinary(reader.Len())
if err != nil {
	fmt.Println(err)
	return err
}
fmt.Println(string(msg))
return nil

}
这里会一直等待,不会触发触发

处理是根本不对!对端没数据,就不会调。

那如何处理才可以接收到超时呢,我看好多功能都已经封起来了,没办法用。还有Server如何主动关闭某一个tcp连接

@Hchenn
Copy link
Contributor

Hchenn commented Jul 5, 2022

你是说空闲超时关闭连接的功能吗?idle timeout 是在 TODO 计划里,当前没有实现。
如果想实现,当前只能注册 WithOnPrepare 后,加一个空闲超时关闭连接的逻辑。

@Yajun312890225
Copy link
Author

你是说空闲超时关闭连接的功能吗?idle timeout 是在 TODO 计划里,当前没有实现。 如果想实现,当前只能注册 WithOnPrepare 后,加一个空闲超时关闭连接的逻辑。

我有一个场景是 客户端和服务端建立tcp/udp连接,服务端作为client和另外一个服务端建立连接,然后将数据传输过去,netpool是否适用于这种场景呢

@Yajun312890225
Copy link
Author

Yajun312890225 commented Jul 5, 2022

你是说空闲超时关闭连接的功能吗?idle timeout 是在 TODO 计划里,当前没有实现。 如果想实现,当前只能注册 WithOnPrepare 后,加一个空闲超时关闭连接的逻辑。

func prepare(connection netpoll.Connection) context.Context { connection.SetDeadline(time.Now().Add(time.Second * 10)) return context.Background() }

我在WithOnPrepare实现SetDeadline依旧没得效果的

@Hchenn
Copy link
Contributor

Hchenn commented Jul 14, 2022

你是说空闲超时关闭连接的功能吗?idle timeout 是在 TODO 计划里,当前没有实现。 如果想实现,当前只能注册 WithOnPrepare 后,加一个空闲超时关闭连接的逻辑。

我有一个场景是 客户端和服务端建立tcp/udp连接,服务端作为client和另外一个服务端建立连接,然后将数据传输过去,netpool是否适用于这种场景呢

直接使用框架吧,kitex 和 hertz 都开源了,自行从头开发貌似没必要。

@Yajun312890225
Copy link
Author

kitex 和 hertz 都开源了 不适用,我这边主要是tcp和udp

@lancer05
Copy link

你是说空闲超时关闭连接的功能吗?idle timeout 是在 TODO 计划里,当前没有实现。 如果想实现,当前只能注册 WithOnPrepare 后,加一个空闲超时关闭连接的逻辑。

func prepare(connection netpoll.Connection) context.Context { connection.SetDeadline(time.Now().Add(time.Second * 10)) return context.Background() }

我在WithOnPrepare实现SetDeadline依旧没得效果的

WithIdleTimeout 这个 还不能用吗? 我调用connection.SetDeadline这个方法,会报错:netpoll dose not support SetDeadline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Development

No branches or pull requests

3 participants