nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.25k stars 320 forks source link

Error 503, PHP #1314

Open Kemel91 opened 1 week ago

Kemel91 commented 1 week ago

For some reason, error 503 appears periodically, and after that it does not go away until the next restart of the container, what could be the problem? Logs:

2024/06/13 04:30:52 [info] 434#434 "laravel" application started
free(): invalid pointer
2024/06/13 04:30:52 [alert] 84#84 app process 412 exited on signal 6
munmap_chunk(): invalid pointer
2024/06/13 04:30:52 [alert] 84#84 app process 427 exited on signal 6
free(): invalid pointer
2024/06/13 04:30:52 [alert] 84#84 app process 370 exited on signal 6
2024/06/13 04:30:54 [info] 438#438 "laravel" application started
free(): invalid pointer
2024/06/13 04:30:55 [alert] 84#84 app process 414 exited on signal 6
2024/06/13 04:30:57 [info] 440#440 "laravel" application started
2024/06/13 04:30:57 [info] 441#441 "laravel" application started
2024/06/13 04:30:57 [alert] 84#84 app process 432 exited on signal 11
2024/06/13 04:30:57 [info] 442#442 "laravel" application started
2024/06/13 04:30:57 [alert] 84#84 app process 406 exited on signal 11
2024/06/13 04:30:57 [alert] 84#84 app process 438 exited on signal 11
2024/06/13 04:31:27 [info] 443#443 "laravel" application started
2024/06/13 04:31:27 [alert] 84#84 app process 426 exited on signal 11

There is more than 100 GB of free RAM on the server, there are no restrictions in the container. Unit config:

{
  "listeners": {
    "*:8082": {
      "pass": "routes"
    }
  },

  "routes": [
    {
      "match": {
        "uri": "!/index.php"
      },
      "action": {
        "share": "/var/www/html/public$uri",
        "fallback": {
          "pass": "applications/laravel"
        }
      }
    }
  ],

  "applications": {
    "laravel": {
      "type": "php",
      "root": "/var/www/html/public/",
      "script": "index.php",
      "processes": {
        "max": 500,
        "spare": 20,
        "idle_timeout": 20
      }
    }
  }
}

PHP 8.3 unit version: 1.32.1 PHP ini memory limit increased to 10 GB.

ac000 commented 1 week ago

Are you getting coredumps? (might not be enabled)

I would really like to see a backtrace from one

$ gdb /path/to/unitd /path/to/coredump
(gdb) bt full

Or if your running systemd then it may be intercepting the core dumps,

$ coredumpctl

If that shows a list, good stuff

$ coredumpctl gdb

Will launch gdb on the most recent coredump...

Kemel91 commented 2 days ago

Are you getting coredumps? (might not be enabled)

I would really like to see a backtrace from one

$ gdb /path/to/unitd /path/to/coredump
(gdb) bt full

Or if your running systemd then it may be intercepting the core dumps,

$ coredumpctl

If that shows a list, good stuff

$ coredumpctl gdb

Will launch gdb on the most recent coredump...

How I can enable coredumps in unitd processes? I can't find anything in doc this info, about enabling coredumps in unitd. How i can do this in docker container?

ac000 commented 2 days ago

Not really a Unit specific thing...

In the container what does

$ cat /proc/sys/kernel/core_pattern

return?

When unit is running what does

$ cat /proc/`pidof -s unitd`/limits

show?

Kemel91 commented 2 days ago

2024-06-24 18 58 37

Not really a Unit specific thing...

In the container what does

$ cat /proc/sys/kernel/core_pattern

return?

When unit is running what does

$ cat /proc/`pidof -s unitd`/limits

show?

cat /proc/sys/kernel/core_pattern /tmp/core

cat /proc/pidof -s unitd/limits:|

Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size unlimited unlimited bytes Max resident set unlimited unlimited bytes Max processes 1048576 1048576 processes Max open files 1048576 1048576 files Max locked memory 8388608 8388608 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 1030780 1030780 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us

ac000 commented 2 days ago

OK, so according to that you should be betting core dumps in /tmp/ named core or possibly core.pid (depending on the setting of /proc/sys/kernel/core_uses_pid). See anything there?

ac000 commented 1 day ago

If you find a core file. You can do

$ gdb /path/to/uniid /path/to/corefile
(gdb) bt full
"Might need to press 'c' to get the full thing"

Alternatively if you are able to create a minimal reproducer...

Kemel91 commented 1 day ago

If you find a core file. You can do

$ gdb /path/to/uniid /path/to/corefile
(gdb) bt full
"Might need to press 'c' to get the full thing"

Alternatively if you are able to create a minimal reproducer...

Thanks for the answer. Another question, are dumps uploaded only when a unitd crashes or can they be uploaded when some process crashes?

ac000 commented 1 day ago

Coredumps are a standard UNIX (and other OS's) feature and will generally be generated for any processes that crash, or when receiving a signal whose default action is to coredump, (SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGQUIT, SIGSEGV, SIGSYS, SIGTRAP, SIGXCPU, SIGXFSZ).

You can also force a running process to coredump via gcore(1)