英文:
Will defer function still get executed after a Kubernetes admission request has timed out?
问题
例如,延迟函数在 webhook 的逻辑中实现(webhook 是用 Golang 编写的)。如果 webhook 在完成之前超时,延迟函数是否仍会执行?
请求超时是通过 context.WithTimeout 来设置 webhook 的。
英文:
For example, a defer function is implemented within a webhook's logic (the webhook is written in Golang). The webhook times out after taking too long to complete. In this case, will the defer function still get executed?
The request timeout is set via context.WithTimeout for the webhook.
答案1
得分: 2
通常最好明确提到你正在谈论的编程语言,尽管我可以弄清楚。
在Go语言中,延迟函数(无论你想如何称呼它)将在方法返回时执行,无论它如何完成,除非你以激烈的方式终止执行过程,甚至在那种情况下也可能执行。
英文:
It's usually a good idea to clearly mention what programming language you're talking about, although I can figure it out.
In Go, the defer functor (whatever you want to call it) will be executed when the method returns, no matter how it completes, unless you manage to kill the executing process in a drastic manner, and perhaps even then.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论