Use GDB debugging to find out the cause of nginx crash

Source: Internet
Author: User

One day in a certain month, an engineer came to me and said: many users complained that the app was rolling back frequently. He thought the server was running normally and could not find the reason. Please help me.

Check the process and find that nginx access logs contain a large number of HTTP 504 err codes.

Tail-F/var/log/messages

A large number of similar error messages

Nginx [1234]: segfault at 0000000000000008 rip 000000000043edf8 RSP route 7fff34a21fa0 error 4

Segfault can only be used with GDB, which is also a benefit for Linux server. It is very troublesome to switch to the Microsoft platform.

The solution is divided into four steps:

  1. The coredump file generated by the configuration system is simple.

    Ulimit-

    The first line is about the Core File Settings. By default, the coredump file is not generated.ulimit -c 1024Remember to use it after debugging is complete.ulimit -c 0Close, or your hard disk will soon be filled up

  2. For GDB debugging, You Need To debug nginx to locate the source code, so you need to recompile an nginx

    First, back up the existing nginx bin directory and conf directory.

    Then print the original nginx compilation options

    /Opt/nginx/sbin/nginx-V

    Add -- With-Debug on this basis and make a copy again.

    Find the compiled nginx in the $ {NGINX-SOURCE-DIR} $/objs directory and copy it to your nginx running directory. Remember not to make install because it will overwrite your nginx. conf file.

  3. Run nginx again and wait for the core. xxx file to be generated. Generally, it is generated in the current directory.

  4. Use GDB to load the coredump File

    GDB -- core = core. xxx

    GDB> where

It is easy to find the reason for nginx segfault: In an nginx modules we write ourselves, some parameters are not checked for the boundary, but after the external environment changes, the NULL pointer is accessed.

Ending:

  • Ulimit-C 0: Turn off coredump

  • After the code is changed, re-compile an nginx without debugging information.

From: http://lutaf.com/140.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.