Search code examples
goprotocol-bufferscode-generation

Protogen goroutine stack exceeds


Recently i've run into a problem with code generation in golang. I have a huge proto file and now need to add logging to most of the messages, using external package. However, if i add logging for too many fields, generation panics, saying that goroutine stack exceeded. Is there a way to generate code by chunks, or increase goroutine max cache size for the generation only?

I tried to debug.SetMaxStack and run generate command with go code, but nothing changed, and it doesn't seem as a good solution for me


Solution

  • Turns out the problem was, as @BurakSerdar said in the comment recursive printing loop. So if you have something like:

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

    You shouldn't do that:

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

    I believe the same goes about other custom things that you want to add to fields, if you have message, containing fields with the type of the same message