Kubernetes准入请求超时后,延迟函数是否仍会执行?

huangapple go评论86阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2021年12月21日 07:58:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/70429270.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定