我想通过Go取消Google PubSub订阅。它在本地运行良好,但是当我在Cloud Run上部署它时,就不可能提取任何消息。
这是我的代码段
func (pubSubService *pubSubService) Received() (msgArray []*pubsub.Message, err error) {
ctx := context.Background()
cctx, cancel := context.WithCancel(ctx)
msgArray = []*pubsub.Message{}
var receivedMessage = make(chan *pubsub.Message)
go func() {
for {
select {
case msg := <-receivedMessage:
msgArray = append(msgArray, msg)
case <-time.After(pubSubService.waitTimeOutInMillis * time.Millisecond):
cancel()
}
}
}()
err = pubSubService.client.Subscription(pubSubService.subscriptionName).Receive(cctx, func(ctx context.Context, msg *pubsub.Message) {
receivedMessage <- msg
msg.Ack()
})
if err != nil {
return
}
return
}
这是日志错误
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x7,0x6,0x12,0xc00006f204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x5,0x6,0x12,0xc0003c1204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0xa,0x6,0x12,0xc0003bd204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0xc,0x6,0x12,0xc00037d204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x6,0x6,0x12,0xc0002d3204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x8,0x6,0x12,0xc00052b204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x9,0x6,0x12,0xc000391204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0xb,0x6,0x12,0xc00043b204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x6,0x6,0x12,0xc0003b3204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0xc,0x6,0x12,0xc0003d3204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x7,0x6,0x12,0xc000391204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0x5,0x6,0x12,0xc000309204,0x4,0x0)
D Container Sandbox Limitation: Unsupported syscall setsockopt(0xb,0x6,0x12,0xc0004d3204,0x4,0x0)
已收到的呼叫由Cloud Run的GVisor沙箱过滤
您知道要为此问题设置的workarround或ReceiveSetting吗? 预先感谢。
答案 0 :(得分:1)
不,这是错误的。我发现了我的问题:我高估了GCP全球网络:我取消轮询的超时设置为200ms。有了这一要求,我的应用没有时间恢复取消前的第一条消息。有了2000ms的超时,它可以完美工作!
Cloud运行允许使用Go例程,但是在http请求回复后它们无法生存。
答案 1 :(得分:0)
拉订阅在Cloud Run中不起作用,因为容器受到限制,甚至终止于请求范围之外。
goroutine无法继续。