1

From times to times my Go program crashes.

I tried a few things in order to get core dumps generated for this program:

  1. defining ulimit on the system, I tried both ulimit -c unlimited and ulimit -c 10000 just in case. After launching my panicking program, I get no core dump.

  2. I also added recover() support in my program and added code to log to syslog in case of panic but I get nothing in syslog.

I am running out of ideas right now.

I must have overlooked something but I do not find what, any help would be appreciated.

Thanks ! :)

kostix
  • 51,517
  • 14
  • 93
  • 176
Jérôme R
  • 1,227
  • 2
  • 13
  • 23

2 Answers2

4

Note that a core dump is generated by the OS when a condition from a certain set is met. These conditions are pretty low-level — like trying to access unmapped memory or trying to execute an opcode the CPU does not know etc. Under a POSIX operating system such as Linux when a process does one of these things, an appropriate signal is sent to it, and some of them, if not handled by the process, have a default action of generating a core dump, which is done by the OS if not prohibited by setting a certain limit.

Now observe that this machinery treats a process on the lowest possible level (machine code), but the binaries a Go compiler produces are more higher-level that those a C compiler (or assembler) produces, and this means certain errors in a process produced by a Go compiler are handled by the Go runtime rather than the OS. For instance, a typical NULL pointer dereference in a process produced by a C compiler usually results in sending the process the SIGSEGV signal which is then typically results in an attempt to dump the process' core and terminate it. In contrast, when this happens in a process compiled by a Go compiler, the Go runtime kicks in and panics, producing a nice stack trace for debugging purposes.

With these facts in mind, I would try to do this:

  1. Wrap your program in a shell script which first relaxes the limit for core dumps (but see below) and then runs your program with its standard error stream redirected to a file (or piped to the logger binary etc).
  2. The limits a user can tweak have a hierarchy: there are soft and hard limits — see this and this for an explanation. So try checking your system does not have 0 for the core dump size set as a hard limit as this would explain why your attempt to raise this limit has no effect.
  3. At least on my Debian systems, when a program dies due to SIGSEGV, this fact is logged by the kernel and is visible in the syslog log files, so try grepping them for hints.
Community
  • 1
  • 1
kostix
  • 51,517
  • 14
  • 93
  • 176
0
  1. First, please make sure all errors are handled.

  2. For core dump, you can refer generate a core dump in linux

  3. You can use supervisor to reboot the program when it crashes.

Community
  • 1
  • 1
Joe
  • 6,460
  • 1
  • 19
  • 15