Home  >  Article  >  Backend Development  >  Protogen Goroutine stack exceeds

Protogen Goroutine stack exceeds

王林
王林forward
2024-02-09 09:48:09822browse

Protogen Goroutine 堆栈超过

php Xiaobian Yuzai today will introduce to you a problem related to Protogen: the situation when the Goroutine stack exceeds. When developing with Protogen, sometimes you will encounter an error message indicating that the Goroutine stack exceeds. The occurrence of this problem may cause program crashes or performance degradation. So, why does this problem occur and how to solve it? Next, we will answer them one by one.

Question content

Recently I encountered a code generation problem in golang. I have a huge raw file and now need to add logging to most of the messages using an external package. However, if I add logging for too many fields, it panics and says the goroutine stack is exceeded. Is there a way to generate code in chunks, or just increase the maximum cache size of generated goroutines?

I tried debug.SetMaxStack and running the build command with go code but nothing changed, it didn't seem like a good solution to me

Workaround

It turns out, The problem is, as @BurakSerdar said in the comment about the recursive print loop. So if you have something like:

message human {
  string name = 1;
  human child = 2;
  human parent = 3;
}

You shouldn’t do this:

message human {
  string name = 1;
  human child = 2 [(logger.field) = true];
  human parent = 3;
}

I believe the same goes for other customizations you want to add to fields, if you have a message that contains a field with the same message type

The above is the detailed content of Protogen Goroutine stack exceeds. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Using go's socks5 proxyNext article:Using go's socks5 proxy