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

如何感知请求已结束? #855

Open
peng19940915 opened this issue Jul 13, 2023 · 12 comments
Open

如何感知请求已结束? #855

peng19940915 opened this issue Jul 13, 2023 · 12 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@peng19940915
Copy link

比如请求中间突然断开了,而此时有一个任务正在执行(如在远程pod上执行一段命令),希望感知到这次断开,并做出对应的清理工作,我看了gin框架使用的net/http是支持该特性的:ctx.Done(), 给每个请求都创建了一个channel
但翻了下hertz以前的issue,发现你们觉得该特性会带来很大性能开销,类似场景hertz有无更好的解决思路?

@github-actions github-actions bot added the invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) label Jul 13, 2023
@github-actions
Copy link

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.

@github-actions github-actions bot added the stale label Jul 13, 2023
@welkeyever
Copy link
Member

本质上其实是想要一个链接断开的时候被cancel的ctx?

@welkeyever welkeyever added question Further information is requested WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed invalid issue invalid issue (not related to Hertz or described in document or not enough information provided) stale labels Jul 13, 2023
@peng19940915
Copy link
Author

本质上其实是想要一个链接断开的时候被cancel的ctx?

嗯嗯,只要能感知到链接断开就行

@welkeyever welkeyever added enhancement New feature or request and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Jul 14, 2023
@welkeyever
Copy link
Member

welkeyever commented Jul 14, 2023

翻了一下标准库的实现,你指的是https://github.com/golang/go/blob/master/src/net/http/server.go#L2011 这个地方的cancel吗,这个cancel比较粗暴,handler执行完毕就cancel了,而非链接关闭才执行;

目前 netpoll 网络库应该能做到真正链接断开的时候cancel上下文,不过这部分最好能够和标准网络库实现对齐。

@xiaotushaoxia
Copy link

xiaotushaoxia commented Aug 2, 2023

你的需求是。“当一个请求过来的时候你阻塞地调用一个函数(函数第一个参数是ctx),你希望客户端断开tcp连接的时候可以让ctx Done” 吗。
@peng19940915

@peng19940915
Copy link
Author

你的需求是。“当一个请求过来的时候你阻塞地调用一个函数(函数第一个参数是ctx),你希望客户端断开tcp连接的时候可以让ctx Done” 吗。 @peng19940915

差不多吧,核心需求是希望因为网络中断等原因导致客户端与hertz断开了,hertz要能感知到,感知到后才能做出相应的资源回收动作

@peng19940915
Copy link
Author

xiaotushaoxia

抱歉这么晚才回复,hertz有办法能实现嘛?目前业务上有类似场景,用户发起了一个请求,服务端调用了一个第三方程序,但有时候用户主动断开请求后,第三方程序还是在跑

@xiaotushaoxia
Copy link

xiaotushaoxia

抱歉这么晚才回复,hertz有办法能实现嘛?目前业务上有类似场景,用户发起了一个请求,服务端调用了一个第三方程序,但有时候用户主动断开请求后,第三方程序还是在跑

我也没找到,可能要换上websocket吧 这样可以知道连接有没有断开

@li-jin-gou
Copy link
Member

li-jin-gou commented Aug 29, 2023

xiaotushaoxia

抱歉这么晚才回复,hertz有办法能实现嘛?目前业务上有类似场景,用户发起了一个请求,服务端调用了一个第三方程序,但有时候用户主动断开请求后,第三方程序还是在跑

hi,@xiaotushaoxia @peng19940915 可以飞书联系聊下,如果在生产环境下使用 hertz 并且的确是真实需求的话我们可以优先支持一下。

@chaoranz758
Copy link
Member

plz assign to me

@liqiaoyang-pm
Copy link

你好,这个问题最后解决了吗,我最近也有一个这个需求,在gin中可以感知到,但是hertz就是不行

@li-jin-gou
Copy link
Member

你好,这个问题最后解决了吗,我最近也有一个这个需求,在gin中可以感知到,但是hertz就是不行

在这个 PR 跟进,没赶上 0.9.0 ,下周争取合入 #1054

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

Successfully merging a pull request may close this issue.

6 participants