Professional Web Applications Themes

#40544 [NEW]: PostgreSQL connection hangs after die() - PHP Bugs

From: kees at tweakers dot net Operating system: Linux (Debian) PHP version: 5.2.1 PHP Bug Type: PostgreSQL related Bug description: PostgreSQL connection hangs after die() Description: ------------ After opening a db connection to postgresql and executing a query, and after that query a 'die()' php doesnt return to the CLI but hangs Reproduce code: --------------- <? $conn = pg_connect('user=acm dbname=logysis'); echo "Starting\n"; $q = " CREATE TEMPORARY TABLE test (test integer); COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'"; pg_query($conn, $q); die("And now he hangs in a busy wait\n"); ?> Expected result: ---------------- acmabaris:~$ php test.3.php ...

  1. #1

    Default #40544 [NEW]: PostgreSQL connection hangs after die()

    From: kees at tweakers dot net
    Operating system: Linux (Debian)
    PHP version: 5.2.1
    PHP Bug Type: PostgreSQL related
    Bug description: PostgreSQL connection hangs after die()

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a busy
    wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program name
    Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2


    --
    Edit bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40544&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40544&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40544&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40544&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40544&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40544&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40544&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40544&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40544&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40544&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40544&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40544&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40544&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40544&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40544&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40544&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40544&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40544&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40544&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40544&r=mysqlcfg[/url]
    kees at tweakers dot net Guest

  2. #2

    Default #40544 [Opn->Fbk]: PostgreSQL connection hangs after die()

    ID: 40544
    Updated by: [email]tony2001php.net[/email]
    Reported By: kees at tweakers dot net
    -Status: Open
    +Status: Feedback
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    New Comment:

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]




    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-19 14:57:19] kees at tweakers dot net

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a
    busy wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program
    name Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    tony2001@php.net Guest

  3. #3

    Default #40544 [Com]: PostgreSQL connection hangs after die()

    ID: 40544
    Comment by: acm at tweakers dot net
    Reported By: kees at tweakers dot net
    Status: Feedback
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    New Comment:

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-19 15:10:06] [email]tony2001php.net[/email]

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]



    ------------------------------------------------------------------------

    [2007-02-19 14:57:19] kees at tweakers dot net

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a
    busy wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program
    name Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    acm at tweakers dot net Guest

  4. #4

    Default #40544 [Fbk->Opn]: PostgreSQL connection hangs after die()

    ID: 40544
    User updated by: kees at tweakers dot net
    Reported By: kees at tweakers dot net
    -Status: Feedback
    +Status: Open
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    New Comment:

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-19 15:19:10] acm at tweakers dot net

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881

    ------------------------------------------------------------------------

    [2007-02-19 15:10:06] [email]tony2001php.net[/email]

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]



    ------------------------------------------------------------------------

    [2007-02-19 14:57:19] kees at tweakers dot net

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a
    busy wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program
    name Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    kees at tweakers dot net Guest

  5. #5

    Default #40544 [Opn->Asn]: PostgreSQL connection hangs after die()

    ID: 40544
    Updated by: [email]tony2001php.net[/email]
    Reported By: kees at tweakers dot net
    -Status: Open
    +Status: Assigned
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    -Assigned To:
    +Assigned To: yohgaki


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-19 15:52:58] kees at tweakers dot net

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)

    ------------------------------------------------------------------------

    [2007-02-19 15:19:10] acm at tweakers dot net

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881

    ------------------------------------------------------------------------

    [2007-02-19 15:10:06] [email]tony2001php.net[/email]

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]



    ------------------------------------------------------------------------

    [2007-02-19 14:57:19] kees at tweakers dot net

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a
    busy wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program
    name Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    tony2001@php.net Guest

  6. #6

    Default #40544 [Com]: PostgreSQL connection hangs after die()

    ID: 40544
    Comment by: yohgaki at ohgaki dot net
    Reported By: kees at tweakers dot net
    Status: Assigned
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    Assigned To: yohgaki
    New Comment:

    Since COPY is not a actual SQL statement, PostgreSQL waits forever
    until COPY ends because the input is STDIN. (SQL Statements like
    SELECT, UPDATE, DELETE, INSERT will be aborted if there is deadlock)

    Since PQfinish() (Used while shutting down pgsql connections) does not
    have option to wait certain amount of time to force closing connection,
    I'm not sure if it is feasible shutting down w/o waiting to finish COPY,
    etc. It's possible to force close connection manually using internal
    PGconn strucutre's connection parameter, but there would be portability
    issues if it use PGconn internal parameters.

    I'll see if there is I can do about this in feasible manner.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-02-19 15:52:58] kees at tweakers dot net

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)

    ------------------------------------------------------------------------

    [2007-02-19 15:19:10] acm at tweakers dot net

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881

    ------------------------------------------------------------------------

    [2007-02-19 15:10:06] [email]tony2001php.net[/email]

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]



    ------------------------------------------------------------------------

    [2007-02-19 14:57:19] kees at tweakers dot net

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a
    busy wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program
    name Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    yohgaki at ohgaki dot net Guest

  7. #7

    Default #40544 [Com]: PostgreSQL connection hangs after die()

    ID: 40544
    Comment by: yohgaki at ohgaki dot net
    Reported By: kees at tweakers dot net
    Status: Assigned
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    Assigned To: yohgaki
    New Comment:

    I didn't look the backtrace carefully. It stops when PQclear() is
    called on the backtrace, while my PHP 5.2 stopeed at PQgetReuslt().
    (Both of them are called when request is shutting down)

    For at least PHP 5.2, it would be solved by calling PQcanel() when
    cleaning up resource, but with compatibility issue. By calling
    PQcanel() before clean up resource, all async query which is not
    finished yet will be discarded instead of finishing its query.

    I'll add new ini option that enables PQcancel() in
    list_entry_destructor. Any comments?


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-07 22:09:55] yohgaki at ohgaki dot net

    Since COPY is not a actual SQL statement, PostgreSQL waits forever
    until COPY ends because the input is STDIN. (SQL Statements like
    SELECT, UPDATE, DELETE, INSERT will be aborted if there is deadlock)

    Since PQfinish() (Used while shutting down pgsql connections) does not
    have option to wait certain amount of time to force closing connection,
    I'm not sure if it is feasible shutting down w/o waiting to finish COPY,
    etc. It's possible to force close connection manually using internal
    PGconn strucutre's connection parameter, but there would be portability
    issues if it use PGconn internal parameters.

    I'll see if there is I can do about this in feasible manner.

    ------------------------------------------------------------------------

    [2007-02-19 15:52:58] kees at tweakers dot net

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)

    ------------------------------------------------------------------------

    [2007-02-19 15:19:10] acm at tweakers dot net

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881

    ------------------------------------------------------------------------

    [2007-02-19 15:10:06] [email]tony2001php.net[/email]

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]



    ------------------------------------------------------------------------

    [2007-02-19 14:57:19] kees at tweakers dot net

    Description:
    ------------
    After opening a db connection to postgresql and executing a query, and
    after that query a 'die()' php doesnt return to the CLI but hangs

    Reproduce code:
    ---------------
    <?
    $conn = pg_connect('user=acm dbname=logysis');

    echo "Starting\n";

    $q = "
    CREATE TEMPORARY TABLE test (test integer);
    COPY test FROM STDIN WITH DELIMITER ',' CSV QUOTE '\"' ESCAPE '\"'";
    pg_query($conn, $q);
    die("And now he hangs in a busy wait\n");
    ?>


    Expected result:
    ----------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait
    acmabaris:~$


    Actual result:
    --------------
    acmabaris:~$ php test.3.php
    Starting
    And now he hangs in a busy wait

    [no prompt, you have to ctrl-c to exit]

    Last part of strace:
    recv(3, "C\0\0\0\21CREATE TABLE\0G\0\0\0\t\0\0\1\0\0", 16384, 0) = 28
    write(1, "And now he hangs in a busy wait\n", 32And now he hangs in a
    busy wait
    ) = 32
    close(6) = 0
    close(5) = 0
    close(4) = 0

    He probably wants to do a close(3) here as that is the postgresql
    connection, but it never closes, and netstat will show an open
    connection:
    Active UNIX domain sockets (servers and established)
    Proto RefCnt Flags Type State I-Node PID/Program
    name Path
    unix 3 [ ] STREAM CONNECTED 549701 -
    /var/run/postgresql/.s.PGSQL.5432
    unix 3 [ ] STREAM CONNECTED 549700 26884/php

    Tested with PHP 5.2.0-8 (debian package) and PHP 4.4.2



    ------------------------------------------------------------------------


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    yohgaki at ohgaki dot net Guest

  8. #8

    Default #40544 [Asn]: PostgreSQL connection hangs after die()

    ID: 40544
    Updated by: [email]tony2001php.net[/email]
    Reported By: kees at tweakers dot net
    Status: Assigned
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    Assigned To: yohgaki
    New Comment:
    >By calling PQcanel() before clean up resource, all async query which
    >is not finished yet will be discarded instead of finishing its query.

    And that's something I would call expected, because "rollback on
    shutdown" is much safer than "commit on shutdown".
    >I'll add new ini option that enables PQcancel() in
    >list_entry_destructor. Any comments?
    More INI options? No, thanks.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-08 04:24:24] yohgaki at ohgaki dot net

    I didn't look the backtrace carefully. It stops when PQclear() is
    called on the backtrace, while my PHP 5.2 stopeed at PQgetReuslt().
    (Both of them are called when request is shutting down)

    For at least PHP 5.2, it would be solved by calling PQcanel() when
    cleaning up resource, but with compatibility issue. By calling
    PQcanel() before clean up resource, all async query which is not
    finished yet will be discarded instead of finishing its query.

    I'll add new ini option that enables PQcancel() in
    list_entry_destructor. Any comments?

    ------------------------------------------------------------------------

    [2007-03-07 22:09:55] yohgaki at ohgaki dot net

    Since COPY is not a actual SQL statement, PostgreSQL waits forever
    until COPY ends because the input is STDIN. (SQL Statements like
    SELECT, UPDATE, DELETE, INSERT will be aborted if there is deadlock)

    Since PQfinish() (Used while shutting down pgsql connections) does not
    have option to wait certain amount of time to force closing connection,
    I'm not sure if it is feasible shutting down w/o waiting to finish COPY,
    etc. It's possible to force close connection manually using internal
    PGconn strucutre's connection parameter, but there would be portability
    issues if it use PGconn internal parameters.

    I'll see if there is I can do about this in feasible manner.

    ------------------------------------------------------------------------

    [2007-02-19 15:52:58] kees at tweakers dot net

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)

    ------------------------------------------------------------------------

    [2007-02-19 15:19:10] acm at tweakers dot net

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881

    ------------------------------------------------------------------------

    [2007-02-19 15:10:06] [email]tony2001php.net[/email]

    Please try using this CVS snapshot:

    [url]http://snaps.php.net/php5.2-latest.tar.gz[/url]

    For Windows:

    [url]http://snaps.php.net/win32/php5.2-win32-latest.zip[/url]



    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    [url]http://bugs.php.net/40544[/url]

    --
    Edit this bug report at [url]http://bugs.php.net/?id=40544&edit=1[/url]
    tony2001@php.net Guest

  9. #9

    Default #40544 [Com]: PostgreSQL connection hangs after die()

    ID: 40544
    Comment by: yohgaki at ohgaki dot net
    Reported By: kees at tweakers dot net
    Status: Assigned
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    Assigned To: yohgaki
    New Comment:
     

    As I wrote, under normal condition, current code(commit on shutdown)
    does make more sense than rollback on shutdown because PostgreSQL
    supports async query.

    'Rollback on shutdown' is like 'Don't flush buffer before closing
    file'. It does not acceptable for most people. (And more efficient if it
    finish pending query at shutdown, too. If you are curious, take some
    simple benchmarks)

    However, under shared environment, it is not acceptable to consume all
    connection by COPY FROM SDTIN. It is better to have a way to avoid such
    action.

    There are 2 options:

    1) Leave it alone (and make DoS possible under shared environment)

    2) Give administrators a option that cancel current and pending async
    query.

    I prefer first option. I'll ask PostgreSQL developer if it's possible
    to have GRANT option for COPY in the future.


    Previous Comments:
    ------------------------------------------------------------------------

    [2007-03-09 10:11:12] net
     


    And that's something I would call expected, because "rollback on
    shutdown" is much safer than "commit on shutdown".
     

    More INI options? No, thanks.

    ------------------------------------------------------------------------

    [2007-03-08 04:24:24] yohgaki at ohgaki dot net

    I didn't look the backtrace carefully. It stops when PQclear() is
    called on the backtrace, while my PHP 5.2 stopeed at PQgetReuslt().
    (Both of them are called when request is shutting down)

    For at least PHP 5.2, it would be solved by calling PQcanel() when
    cleaning up resource, but with compatibility issue. By calling PQcanel()
    before clean up resource, all async query which is not finished yet will
    be discarded instead of finishing its query.

    I'll add new ini option that enables PQcancel() in
    list_entry_destructor. Any comments?

    ------------------------------------------------------------------------

    [2007-03-07 22:09:55] yohgaki at ohgaki dot net

    Since COPY is not a actual SQL statement, PostgreSQL waits forever
    until COPY ends because the input is STDIN. (SQL Statements like SELECT,
    UPDATE, DELETE, INSERT will be aborted if there is deadlock)

    Since PQfinish() (Used while shutting down pgsql connections) does not
    have option to wait certain amount of time to force closing connection,
    I'm not sure if it is feasible shutting down w/o waiting to finish COPY,
    etc. It's possible to force close connection manually using internal
    PGconn strucutre's connection parameter, but there would be portability
    issues if it use PGconn internal parameters.

    I'll see if there is I can do about this in feasible manner.

    ------------------------------------------------------------------------

    [2007-02-19 15:52:58] kees at tweakers dot net

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)

    ------------------------------------------------------------------------

    [2007-02-19 15:19:10] acm at tweakers dot net

    Btw, when hanging gdb to the php-process and type 'bt' you get this:

    #0 0xa7ba88c0 in free () from /lib/tls/libc.so.6
    #1 0xa7ec8ea7 in PQclear () from /usr/lib/libpq.so.5
    #2 0x08086fc8 in _close_pgsql_link (rsrc=0x81e43ec) at
    /usr/src/php-4.4.2/ext/pgsql/pgsql.c:277
    #3 0x08139fb2 in list_entry_destructor (ptr=0x81e43ec) at
    /usr/src/php-4.4.2/Zend/zend_list.c:177
    #4 0x08137977 in zend_hash_apply_deleter (ht=0x81a49e0, p=0x81e43b4)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:611
    #5 0x08137b97 in zend_hash_graceful_reverse_destroy (ht=0x81a49e0)
    at /usr/src/php-4.4.2/Zend/zend_hash.c:677
    #6 0x0812b9ed in shutdown_executor () at
    /usr/src/php-4.4.2/Zend/zend_execute_API.c:211
    #7 0x08133801 in zend_deactivate () at
    /usr/src/php-4.4.2/Zend/zend.c:689
    #8 0x08107862 in php_request_shutdown (dummy=0x0) at
    /usr/src/php-4.4.2/main/main.c:999
    #9 0x0814ee56 in main (argc=2, argv=0xafb6d114) at
    /usr/src/php-4.4.2/sapi/cli/php_cli.c:881

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    http://bugs.php.net/40544

    --
    Edit this bug report at http://bugs.php.net/?id=40544&edit=1
    yohgaki Guest

  10. #10

    Default #40544 [Asn]: PostgreSQL connection hangs after die()

    ID: 40544
    Updated by: net
    Reported By: kees at tweakers dot net
    Status: Assigned
    Bug Type: PostgreSQL related
    Operating System: Linux (Debian)
    PHP Version: 5.2.1
    Assigned To: yohgaki
    New Comment:
     
    file'.
    I disagree, you need to commit everything explicitly.
    If you didn't commit the transaction, it should be rolled back.



    Previous Comments:
    ------------------------------------------------------------------------

    [2007-04-05 01:28:11] yohgaki at ohgaki dot net
     

    As I wrote, under normal condition, current code(commit on shutdown)
    does make more sense than rollback on shutdown because PostgreSQL
    supports async query.

    'Rollback on shutdown' is like 'Don't flush buffer before closing
    file'. It does not acceptable for most people. (And more efficient if it
    finish pending query at shutdown, too. If you are curious, take some
    simple benchmarks)

    However, under shared environment, it is not acceptable to consume all
    connection by COPY FROM SDTIN. It is better to have a way to avoid such
    action.

    There are 2 options:

    1) Leave it alone (and make DoS possible under shared environment)

    2) Give administrators a option that cancel current and pending async
    query.

    I prefer first option. I'll ask PostgreSQL developer if it's possible
    to have GRANT option for COPY in the future.

    ------------------------------------------------------------------------

    [2007-03-09 10:11:12] net
     


    And that's something I would call expected, because "rollback on
    shutdown" is much safer than "commit on shutdown".
     

    More INI options? No, thanks.

    ------------------------------------------------------------------------

    [2007-03-08 04:24:24] yohgaki at ohgaki dot net

    I didn't look the backtrace carefully. It stops when PQclear() is
    called on the backtrace, while my PHP 5.2 stopeed at PQgetReuslt().
    (Both of them are called when request is shutting down)

    For at least PHP 5.2, it would be solved by calling PQcanel() when
    cleaning up resource, but with compatibility issue. By calling PQcanel()
    before clean up resource, all async query which is not finished yet will
    be discarded instead of finishing its query.

    I'll add new ini option that enables PQcancel() in
    list_entry_destructor. Any comments?

    ------------------------------------------------------------------------

    [2007-03-07 22:09:55] yohgaki at ohgaki dot net

    Since COPY is not a actual SQL statement, PostgreSQL waits forever
    until COPY ends because the input is STDIN. (SQL Statements like SELECT,
    UPDATE, DELETE, INSERT will be aborted if there is deadlock)

    Since PQfinish() (Used while shutting down pgsql connections) does not
    have option to wait certain amount of time to force closing connection,
    I'm not sure if it is feasible shutting down w/o waiting to finish COPY,
    etc. It's possible to force close connection manually using internal
    PGconn strucutre's connection parameter, but there would be portability
    issues if it use PGconn internal parameters.

    I'll see if there is I can do about this in feasible manner.

    ------------------------------------------------------------------------

    [2007-02-19 15:52:58] kees at tweakers dot net

    tested with the snapshot:

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php test.3.php
    Starting
    And now he hangs in a busy wait

    [ctrl-c]

    acmabaris:/usr/src/php5.2-200702191330$ sapi/cli/php -v
    PHP 5.2.2-dev (cli) (built: Feb 19 2007 16:49:22)
    Copyright (c) 1997-2007 The PHP Group
    Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies

    ldd sapi/cli/php
    libpq.so.5 => /usr/lib/libpq.so.5 (0xa7f3c000)

    ------------------------------------------------------------------------

    The remainder of the comments for this report are too long. To view
    the rest of the comments, please view the bug report online at
    http://bugs.php.net/40544

    --
    Edit this bug report at http://bugs.php.net/?id=40544&edit=1
    tony2001@php.net Guest

Similar Threads

  1. ASP page hangs on opening connection object to mdb database
    By Mendel Nemanov in forum ASP Database
    Replies: 1
    Last Post: May 6th, 08:28 PM
  2. #22474 [Com]: fwrite hangs on invalid connection
    By kxrm at hotmail dot com in forum PHP Development
    Replies: 1
    Last Post: November 4th, 01:14 PM
  3. Replies: 0
    Last Post: October 2nd, 07:31 PM
  4. Replies: 3
    Last Post: July 31st, 04:18 PM
  5. Computer hangs on startup with ADSL connection
    By Allain Pelletier in forum Windows Networking
    Replies: 1
    Last Post: July 5th, 06:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139