Opened 9 years ago

Closed 8 years ago

#2775 closed defect (fixed)

Hangs when closing db drivers

Reported by: rblazek Owned by: grass-dev@…
Priority: blocker Milestone: 7.0.3
Component: Database Version: unspecified
Keywords: Cc:
CPU: Unspecified Platform: Linux

Description

Module hangs if db drivers are not closed in revers order to the order in which were opened. For example open driver A, open driver B, close driver A hangs forever on waitpid() in G_wait() because driver process does not exit when its stdin is closed in db_shutdown_driver() by fclose(driver->send). fclose() returns 0 (ok). The driver is probably hanging on db__recv_procnum() even if stdin was closed.

It is fixed by enabling procedure DB_PROC_SHUTDOWN_DRIVER like it is used on Window. Patch attached.

Attachments (2)

close-driver.patch (958 bytes ) - added by rblazek 9 years ago.
close-driver-2-glynn.patch (740 bytes ) - added by rblazek 8 years ago.
Suggested by Glynn, FD_CLOEXEC

Download all attachments as: .zip

Change History (12)

by rblazek, 9 years ago

Attachment: close-driver.patch added

comment:1 by rblazek, 8 years ago

Annother fix suggested by Glynn and resolving the real problem also works https://lists.osgeo.org/pipermail/grass-dev/2015-October/076925.html

        void close_on_exec(int fd)
        {
        #ifndef __MINGW32__
            int flags = fcntl(fd, F_GETFD);
            fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
        #endif
        }

        close_on_exec(p1[READ]);
        close_on_exec(p1[WRITE]);
        close_on_exec(p2[READ]);
        close_on_exec(p2[WRITE]);

Patch attached.

by rblazek, 8 years ago

Attachment: close-driver-2-glynn.patch added

Suggested by Glynn, FD_CLOEXEC

comment:2 by neteler, 8 years ago

Milestone: 7.0.1

To apply the second patch? Also backport it?

comment:3 by rblazek, 8 years ago

More from Glynn about the possibility to close all descriptors https://lists.osgeo.org/pipermail/grass-dev/2015-October/077010.html which does not seem to be optimal.

I think that both patches should be applied. The second is resolving the real problem. The first, explicitly sending close procedure to driver cannot harm and it should also cover all cases when a descriptor is opened (even not db related) without setting FD_CLOEXEC.

Backport would be useful.

comment:4 by martinl, 8 years ago

Milestone: 7.0.17.0.3

comment:5 by neteler, 8 years ago

Priority: normalblocker

Likely relevant for the winGRASS (64bit), promoting to blocker since patches are provided.

comment:6 by martinl, 8 years ago

I took liberty to apply both patches in trunk (r67290). Testing highly welcomed before we do backport to relbr70 (must be done before 7.0.3RC1)

in reply to:  6 ; comment:7 by mlennert, 8 years ago

Replying to martinl:

I took liberty to apply both patches in trunk (r67290). Testing highly welcomed before we do backport to relbr70 (must be done before 7.0.3RC1)

Any ideas of how to test this specifically ?

in reply to:  7 comment:8 by martinl, 8 years ago

Replying to mlennert:

Replying to martinl:

I took liberty to apply both patches in trunk (r67290). Testing highly welcomed before we do backport to relbr70 (must be done before 7.0.3RC1)

Any ideas of how to test this specifically ?

svn cat https://svn.osgeo.org/grass/sandbox/martinl/test-2775.c > test-2775.c
gcc test-2775.c -I/path/to/grassheaders -lgrass_dbmiclient -L/path/to/grasslibs
./a.out

will hang when closing db1

closing db1

comment:9 by martinl, 8 years ago

After testing I took liberty to backport changes also to relbr70 - r67369. Now the sample program finishes successfully also here.

closing db1
closing db2

comment:10 by martinl, 8 years ago

Resolution: fixed
Status: newclosed

Closing the ticket, feel free to re-open if needed.

Note: See TracTickets for help on using tickets.