GithubHelp home page GithubHelp logo

Comments (31)

bjori avatar bjori commented on July 1, 2024
  1. The MongoDB\Collection object needs to be immutable.
    Having it mutable creates lots of problems, even within your application, such as when you call a method you literally don't know what ReadPreference or WriteConcern will be applied unless you set it in the same location -- which in turn means the next operation will have to do the same, again and again, as if it changes anywhere -- in that one place where you needed different ReadPreference or WriteConcern -- then it breaks all other cases.
    These Collection objects are cheap, so you can create many of them -- they have no sideffects, so you could create:
$writeConcern = new WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY);
$myCollectionSecondaryPreferred = new Collection($manager, "myCollection", $writeConcern, new ReadPreference(ReadPreference::RP_SECONDARY_PREFERRED);
$myCollectionPrimary            = new Collection($manager, "myCollection", $writeConcern, new ReadPreference(ReadPreference::RP_PRIMARY);
  1. Are you talking about a limit for find? It is part of the $options argument. $collection->find($query, array("limit" => 42)); should do the trick.
  2. That looks very weird. We'll have to check that out.

from mongo-php-library.

bjori avatar bjori commented on July 1, 2024

Hey, just for the records -- which version of pecl/mongodb are you using, and which version of mongo-php-library-prototype are you using?

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024
  1. Ok, I got it.
  2. I know about find options, but if new MongoDB will have limit method we can use old PHP code. This is compatibility issue.
  3. Tell if I can help you debug this issue. Same code on MongoClient and MongoDB works different.

PHP Version 5.6.12 + mongodb 1.0.0alpha2 + libmongoc version 1.2.0-beta.
https://www.dropbox.com/s/wvvg3dw67ht3keo/Screenshot%202015-08-25%2010.53.06.png?dl=0

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: can you share a script that reproduces your third problem with findOne() not returning a result with its ID?

We do have a test for findOne()'s return value here, and the full document with its _id field is returned (we're not testing the projection options yet, so this is the default behavior).

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Ok, this is code sample for both mongo libraries, old and new one.

<?
$host = 'mongodb://aux.srv.loc:27018';
$options = ['w' => 1, 'journal' => 0, 'connectTimeoutMS' => 10000, 'socketTimeoutMS' => 10000, 'wTimeoutMS' => 10000];

$clients = [
    new \MongoClient($host, $options),
    new MongoDB\Client($host, $options),
];

var_dump(PHP_INT_MAX);

// same code work twice on old and new mondo libralies
foreach ($clients as $client) {
    if (method_exists($client, 'selectDB')) {
        $db = $client->selectDB('goods_archive');
    } else {
        $db = $client->selectDatabase('goods_archive');
    }

    $collection = $db->selectCollection('goods');

    $row = $collection->findOne(['_id' => 274697927]);
    if (is_object($row)) $row = get_object_vars($row);

    var_dump($row);
}
exit;

Check out the _id value, it is different. In old library I search by _id=274697927 and get result with _id=274697927. The new library by _id=274697927 returns row with _id=140460250721256.

New huge _id is not constanе, it is growing all the time. 140460259360248 => 140460259373816 => ...

Can you tell please why in second loop I got such strange _id?

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Any news about _id issue?

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: I'm tracking that issue in PHPC-403 if you'd like to follow that as well, but we can discuss it here. A few questions:

  • Earlier, you said "findOne(['_id' => $id]) call returns item without "_id" property, it is empty (null)." This doesn't agree with your code example above, where the _id simply has an incorrect numeric value. Is this issue (i.e. _id field existing in the document but having a null value) still happening, and if so, is there code to reproduce that.
  • What is PHP_INT_MAX on your system?
  • In the last post, you stated "New huge _id is not constant, it is growing all the time. 140460259360248 => 140460259373816 => etc." Does that number increase each time you execute the test? Can you confirm in the Javascript shell that 274697927 is actually stored as the _id for this document?

I attempted to reproduce this locally using the following test case, which I added to tests/Collection/CollectionFunctionalTest.php:

public function testFindOneDiscardsId()
{
    $bulkWrite = new BulkWrite(true);
    $bulkWrite->insert(array(
        '_id' => 274697927,
        'x' => 1,
    ));

    $result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);

    $this->assertEquals(1, $result->getInsertedCount());

    $document = $this->collection->findOne(array('_id' => 274697927));

    $this->assertEquals(274697927, $document->_id);

    if (is_object($document)) {
        $document = get_object_vars($document);
    }

    var_dump($document);
}

This passes locally for me. Can you try to run this in your own clone of the repository and report back with the results?

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Thank you for answer.

I cant reproduce case then _id became null, this case is linked to type transform. I cant run your test case with BulkWrite now, sorry. Our mongo database is read only. Tried play with _id value access, the only code I run - var_dump($row);

  1. Very offten I got huge number in _id (139671776966232 for example).
  2. About after 6-7 page refresh I got right value "274697927" in _id.
  3. 2-3 refreshes makes seg fault of Apache "[Wed Sep 02 10:50:04.484490 2015] [core:notice] [pid 5016] AH00051: child pid 5121 exit signal Segmentation fault (11), possible coredump in /tmp".
  4. Every time I tried acsess to _id with huge value I got seg fault. Code sample:
    file_put_contents('/home/fedorenko/baza/1.txt', time().'!'.var_export($row, true));
    var_dump($row['_id']); // <-- seg fault

Then seg fault happen, in 1.txt file _id is "true" - https://www.dropbox.com/s/tj7vrw7b92nn26b/Screenshot%202015-09-02%2011.00.51.png?dl=0
5. PHP_INT_MAX on my system is 9223372036854775807.
6. I cant reproduce problem with MongoClient. Seg faults and huge int appiers only with MongoDB\Client + mongodb.so
7. Huge number changes suddenly. Now I got _id=139671776981752 after 6 time execute test case, on 7 run I got new value - 139671776979824.
8. In Javascript shell and with old client I got right _id value - 274697927.

Looks like the problem is in mongo-php-driver-prototype. Wrong work with memory pointer? I will search the way to give you full stack trace from core dump tomorrow.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Here is core dump report:

fedorenko@vm ~ $ sudo gdb /usr/sbin/apache2 /tmp/core
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/sbin/apache2...Reading symbols from /usr/lib/debug//usr/sbin/apache2...done.
done.
[New LWP 2557]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/usr/sbin/apache2 -k start'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007ff12860876a in _zend_hash_add_or_update (ht=0x7ff115bf81d8, arKey=arKey@entry=0x7ff1286b278f "file", nKeyLength=nKeyLength@entry=5,
    pData=pData@entry=0x7fffefcf0bf8, nDataSize=nDataSize@entry=8, pDest=pDest@entry=0x0, flag=flag@entry=1) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_hash.c:260
260 /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_hash.c: No such file or directory.
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'
(gdb) bt
#0  0x00007ff12860876a in _zend_hash_add_or_update (ht=0x7ff115bf81d8, arKey=arKey@entry=0x7ff1286b278f "file", nKeyLength=nKeyLength@entry=5,
    pData=pData@entry=0x7fffefcf0bf8, nDataSize=nDataSize@entry=8, pDest=pDest@entry=0x0, flag=flag@entry=1) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_hash.c:260
#1  0x00007ff1285ffcb4 in zend_symtable_update (nDataSize=8, pDest=0x0, pData=0x7fffefcf0bf8, nKeyLength=5, arKey=0x7ff1286b278f "file", ht=<optimized out>)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_hash.h:359
#2  add_assoc_string_ex (arg=arg@entry=0x7ff12f256410, key=key@entry=0x7ff1286b278f "file", key_len=key_len@entry=5,
    str=0x7ff12ea6f0c0 "/home/fedorenko/baza/slr/request/src/result_handler/slrAjaxResultHandler.class.php", duplicate=duplicate@entry=1)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_API.c:1286
#3  0x00007ff12851fdba in zif_error_get_last (ht=<optimized out>, return_value=0x7ff12f256410, return_value_ptr=<optimized out>, this_ptr=<optimized out>,
    return_value_used=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/ext/standard/basic_functions.c:4739
#4  0x00007ff1285eb31b in dtrace_execute_internal (execute_data_ptr=<optimized out>, fci=<optimized out>, return_value_used=<optimized out>)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_dtrace.c:97
#5  0x00007ff12515ca46 in xdebug_execute_internal (current_execute_data=0x7ff12ca0b780, fci=0x0, return_value_used=1) at /tmp/pear/temp/xdebug/xdebug.c:1553
#6  0x00007ff1286a0724 in zend_do_fcall_common_helper_SPEC (execute_data=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_vm_execute.h:560
#7  0x00007ff128636278 in execute_ex (execute_data=0x7ff12ca0b780) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_vm_execute.h:363
#8  0x00007ff1285eb219 in dtrace_execute_ex (execute_data=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_dtrace.c:73
#9  0x00007ff12515bfcc in xdebug_execute_ex (execute_data=0x7ff12ca0b780) at /tmp/pear/temp/xdebug/xdebug.c:1439
#10 0x00007ff1285ecf43 in zend_call_function (fci=fci@entry=0x7fffefcf1120, fci_cache=<optimized out>, fci_cache@entry=0x0)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_execute_API.c:829
#11 0x00007ff1285ed12e in call_user_function_ex (function_table=function_table@entry=0x7ff12dee36d0, object_pp=<optimized out>, function_name=<optimized out>,
    retval_ptr_ptr=retval_ptr_ptr@entry=0x7fffefcf11b8, param_count=<optimized out>, params=params@entry=0x0, no_separation=no_separation@entry=1,
    symbol_table=symbol_table@entry=0x0) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_execute_API.c:617
#12 0x00007ff1285ed182 in call_user_function (function_table=0x7ff12dee36d0, object_pp=object_pp@entry=0x0, function_name=<optimized out>,
    retval_ptr=retval_ptr@entry=0x7fffefcf11f0, param_count=<optimized out>, params=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_execute_API.c:590
#13 0x00007ff12851e24b in user_shutdown_function_call (shutdown_function_entry=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/ext/standard/basic_functions.c:4974
#14 0x00007ff128609973 in zend_hash_apply (ht=0x7ff12ca44d40, apply_func=apply_func@entry=0x7ff12851e1f0 <user_shutdown_function_call>)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_hash.c:641
#15 0x00007ff128522176 in php_call_shutdown_functions () at /build/php5-gydbSc/php5-5.6.12+dfsg/ext/standard/basic_functions.c:5066
#16 0x00007ff12859a5e5 in php_request_shutdown (dummy=dummy@entry=0x0) at /build/php5-gydbSc/php5-5.6.12+dfsg/main/main.c:1819
#17 0x00007ff1286a218f in php_apache_request_dtor (r=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/sapi/apache2handler/sapi_apache2.c:507
#18 php_handler (r=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/sapi/apache2handler/sapi_apache2.c:679
#19 0x00007ff12cb81fd0 in ap_run_handler (r=0x7ff12c92d0a0) at config.c:169
#20 0x00007ff12cb82519 in ap_invoke_handler (r=r@entry=0x7ff12c92d0a0) at config.c:433
#21 0x00007ff12cb987ba in ap_process_async_request (r=0x7ff12c92d0a0) at http_request.c:338
#22 0x00007ff12cb98a94 in ap_process_request (r=r@entry=0x7ff12c92d0a0) at http_request.c:373
#23 0x00007ff12cb94dee in ap_process_http_sync_connection (c=0x7ff12c933290) at http_core.c:210
#24 ap_process_http_connection (c=0x7ff12c933290) at http_core.c:251
#25 0x00007ff12cb8bb10 in ap_run_process_connection (c=0x7ff12c933290) at connection.c:41
#26 0x00007ff12cb8bf28 in ap_process_connection (c=c@entry=0x7ff12c933290, csd=<optimized out>) at connection.c:213
#27 0x00007ff128fb5767 in child_main (child_num_arg=child_num_arg@entry=4) at prefork.c:704
#28 0x00007ff128fb59a6 in make_child (s=0x7ff12caf0f30, slot=slot@entry=4) at prefork.c:800
#29 0x00007ff128fb5a06 in startup_children (number_to_start=1) at prefork.c:818
#30 0x00007ff128fb66e0 in prefork_run (_pconf=<optimized out>, plog=0x7ff12caea028, s=0x7ff12caf0f30) at prefork.c:976
---Type <return> to continue, or q <return> to quit---
#31 0x00007ff12cb67f0e in ap_run_mpm (pconf=0x7ff12cb1d028, plog=0x7ff12caea028, s=0x7ff12caf0f30) at mpm_common.c:94
#32 0x00007ff12cb616c6 in main (argc=3, argv=0x7fffefcf1bd8) at main.c:777
(gdb)

from mongo-php-library.

bjori avatar bjori commented on July 1, 2024

That backtrace is failing in error_get_last(), not pecl/mongodb.
You may want to try disable xdebug and see if that changes anything.

If that still crashes, try this for me:

$ wget -O gdbinit "http://git.php.net/?p=php-src.git;a=blob_plain;f=.gdbinit;hb=refs/heads/PHP-5.6"
$ sudo gdb /usr/sbin/apache2 /tmp/core
(gdb) source gdbinit
(gdb) set print array on
(gdb) set print object on
(gdb) set print symbol-filename on
(gdb) set print pretty on
(gdb) set height 0
(gdb) bt full
(gdb) frame 2
(gdb) l
(gdb) printzv arg
(gdb) zbacktrace

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Still got seg fault after disable xdebug

fedorenko@vm ~ $ sudo gdb /usr/sbin/apache2 /tmp/core
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/sbin/apache2...Reading symbols from /usr/lib/debug//usr/sbin/apache2...done.
done.
[New LWP 3233]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `/usr/sbin/apache2 -k start'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  _default_exception_get_entry (object=object@entry=0x7ff222fa3d78, name=name@entry=0x7ff234e6c2e9 "message", name_len=name_len@entry=7,
    return_value=return_value@entry=0x7fff82e65d80) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_exceptions.c:298
298 /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_exceptions.c: No such file or directory.
Traceback (most recent call last):
  File "/usr/share/gdb/auto-load/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19-gdb.py", line 63, in <module>
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named 'libstdcxx'
(gdb) source gdbinit
(gdb) set print array on
(gdb) set print object on
(gdb) set print symbol-filename on
(gdb) set print pretty on
(gdb) set height 0
(gdb) bt full
#0  _default_exception_get_entry (object=object@entry=0x7ff222fa3d78, name=name@entry=0x7ff234e6c2e9 "message", name_len=name_len@entry=7,
    return_value=return_value@entry=0x7fff82e65d80) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_exceptions.c:298
        value = 0x7ff222fa5a3000
#1  0x00007ff234a4cf23 in zim_exception___toString (ht=<optimized out>, return_value=0x7ff222fa3e08, return_value_ptr=<optimized out>, this_ptr=0x7ff222fa3d78,
    return_value_used=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_exceptions.c:680
        message = {
          value = {
            lval = 140678313284800,
            dval = 6,9504321708911926e-310,
            str = {
              val = 0x7ff238e414c0 "\340\024\344\070\362\177",
              len = 883768725
            },
            ht = 0x7ff238e414c0,
            obj = {
              handle = 954471616,
              handlers = 0x7ff234ad3d95 <zend_leave_helper_SPEC+981 at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_gc.h:183>
            },
            ast = 0x7ff238e414c0
          },
          refcount__gc = 954471456,
          type = 242 '\362',
          is_ref__gc = 127 '\177'
        }
        line = {
          value = {
            lval = 1,
            dval = 4,9406564584124654e-324,
            str = {
              val = 0x1 <error: Cannot access memory at address 0x1>,
              len = 0
            },
            ht = 0x1,
            obj = {
              handle = 1,
              handlers = 0x0
            },
            ast = 0x1
          },
          refcount__gc = 586823464,
          type = 242 '\362',
          is_ref__gc = 127 '\177'
        }
        exception = 0x7ff222fa3d78
        str = 0x7ff222fa5a10 ""
        fname = {
          value = {
            lval = 140677945643480,
            dval = 6,9504140069965722e-310,
            str = {
              val = 0x7ff222fa51d8 "gettraceasstring",
              len = 16
            },
            ht = 0x7ff222fa51d8,
            obj = {
              handle = 586830296,
              handlers = 0x7ff200000010
            },
            ast = 0x7ff222fa51d8
          },
          refcount__gc = 588422184,
          type = 6 '\006',
          is_ref__gc = 127 '\177'
        }
        file = {
          value = {
            lval = 140677945637360,
            dval = 6,950414006694204e-310,
            str = {
              val = 0x7ff222fa39f0 "\006",
              len = 954471456
            },
            ht = 0x7ff222fa39f0,
            obj = {
              handle = 586824176,
              handlers = 0x7ff238e41420
            },
            ast = 0x7ff222fa39f0
          },
          refcount__gc = 891144704,
          type = 242 '\362',
          is_ref__gc = 127 '\177'
        }
        trace = 0x7ff2351dca00 <executor_globals>
        prev_str = 0x7ff222fa5a10 ""
        fci = {
          size = 140733193388033,
          function_table = 0x7ff23a3f46a0,
          function_name = 0x7ff222fa3c80,
          symbol_table = 0x7ff223129198,
          retval_ptr_ptr = 0x7ff223128e30,
          param_count = 588419480,
          params = 0x0,
          object_ptr = 0x7ff238e41290,
          no_separation = 8 '\b'
        }
        len = 0
        ht = <optimized out>
        return_value = 0x7ff222fa3e08
        return_value_ptr = <optimized out>
        return_value_used = <optimized out>
        this_ptr = 0x7ff222fa3d78
#2  0x00007ff234a2231b in dtrace_execute_internal (execute_data_ptr=<optimized out>, fci=<optimized out>, return_value_used=<optimized out>)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_dtrace.c:97
        lineno = <optimized out>
        filename = <optimized out>
#3  0x00007ff234a24025 in zend_call_function (fci=fci@entry=0x7fff82e660a0, fci_cache=fci_cache@entry=0x7fff82e66070)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_execute_API.c:849
        call_via_handler = 0
        i = <optimized out>
        original_return_value = <optimized out>
        calling_symbol_table = <optimized out>
        original_op_array = <optimized out>
        original_opline_ptr = <optimized out>
        current_scope = 0x0
        current_called_scope = 0x0
        calling_scope = <optimized out>
        called_scope = 0x7ff23a2e08e0
        current_this = 0x0
        execute_data = {
          opline = 0x0,
          function_state = {
            function = 0x7ff23a2e1ee0,
            arguments = 0x7ff238e41060
          },
          op_array = 0x0,
          object = 0x7ff222fa3d78,
          symbol_table = 0x0,
          prev_execute_data = 0x0,
          old_error_reporting = 0x0,
          nested = 0 '\000',
          original_return_value = 0x0,
          current_scope = 0x0,
          current_called_scope = 0x0,
          current_this = 0x0,
          fast_ret = 0x0,
          delayed_exception = 0x0,
          call_slots = 0x0,
          call = 0x0
        }
        fci_cache_local = {
          initialized = 0 '\000',
          function_handler = 0x0,
          calling_scope = 0x1,
          called_scope = 0x7ff2351dcc40 <executor_globals+576>,
          object_ptr = 0x7ff2351c26fc <php_execute.return_semaphore>
        }
#4  0x00007ff234a49dd5 in zend_call_method (object_pp=object_pp@entry=0x7fff82e66148, obj_ce=<optimized out>, obj_ce@entry=0x7ff23a2e08e0, fn_proxy=fn_proxy@entry=0x0,
    function_name=function_name@entry=0x7ff234e5ecf8 "__tostring", function_name_len=function_name_len@entry=10, retval_ptr_ptr=retval_ptr_ptr@entry=0x7fff82e66158,
    param_count=param_count@entry=0, arg1=arg1@entry=0x0, arg2=arg2@entry=0x0) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_interfaces.c:97
        fcic = {
          initialized = 1 '\001',
          function_handler = 0x7ff23a2e1ee0,
          calling_scope = 0x7ff23a2e08e0,
          called_scope = 0x7ff23a2e08e0,
          object_ptr = 0x7ff222fa3d78
        }
        result = <optimized out>
        fci = {
          size = 72,
          function_table = 0x7ff2351dcc40 <executor_globals+576>,
          function_name = 0x7fff82e66050,
          symbol_table = 0x0,
          retval_ptr_ptr = 0x7fff82e66158,
          param_count = 0,
          params = 0x7fff82e66040,
          object_ptr = 0x7ff222fa3d78,
          no_separation = 1 '\001'
        }
        z_fname = {
          value = {
            lval = 423448544,
            dval = 2,092113783718955e-315,
            str = {
              val = 0x193d4fe0 <error: Cannot access memory at address 0x193d4fe0>,
              len = 0
            },
            ht = 0x193d4fe0,
            obj = {
              handle = 423448544,
              handlers = 0x0
            },
            ast = 0x193d4fe0
          },
          refcount__gc = 0,
          type = 0 '\000',
          is_ref__gc = 0 '\000'
        }
        retval = 0x7ff234ad45bd <ZEND_HANDLE_EXCEPTION_SPEC_HANDLER+1197 at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_vm_execute.h:1295>
        function_table = <optimized out>
        params =           {0x7fff82e66138,
          0x7fff82e66140}
#5  0x00007ff234a4d792 in zend_exception_error (exception=0x7ff222fa3d78, severity=severity@entry=1) at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_exceptions.c:893
        str = 0x7ff222fa3e08
        file = <optimized out>
        line = <optimized out>
        ce_exception = 0x7ff23a2e08e0
#6  0x00007ff234a3472a in zend_execute_scripts (type=type@entry=8, retval=retval@entry=0x0, file_count=file_count@entry=3)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend.c:1365
        files =           {{
            gp_offset = 40,
            fp_offset = 1,
            overflow_arg_area = 0x7fff82e66280,
            reg_save_area = 0x7fff82e66210
          }}
        i = 1
        file_handle = 0x7fff82e68500
        orig_op_array = 0x0
        orig_retval_ptr_ptr = 0x0
        orig_interactive = 0
#7  0x00007ff2349d2822 in php_execute_script (primary_file=primary_file@entry=0x7fff82e68500) at /build/php5-gydbSc/php5-5.6.12+dfsg/main/main.c:2597
        realfile =           "\000\000\000\000\000\000\000\000\340\357G8\362\177\000\000\000\000\000\000\000\000\000\000\221\000\000\000\000\000\000\000ъ\031}\000\200\377\377\n\000\000\000\000\000\000\000\002\000\000\000\000\000\000\000\062\000\000\000\000\000\000\000\060u\346\202\377\177", '\000' <repeats 14 times>, "[", '\000' <repeats 19 times>, "n\000\000\000w", '\000' <repeats 11 times>, "/u\346\202\377\177\000\000\001\000\000\000\362\177\000\000`\223Z1\362\177\000\000|\000\000\000\362\177\000\000\230\261\034\070\362\177\000\000\220u\346\202\377\177\000\000\060\000\000\000\060\000\000\000(v\346\202\377\177\000\000Pu\346\202\377\177\000\000\000\000\000\000\000\000\000\000p"...
        __orig_bailout = 0x7fff82e68580
        __bailout =           {{
            __jmpbuf =               {140678312370336,
              4787705847465654397,
              140678312370336,
              140678317207584,
              140735389534060,
              140678312403600,
              4787705855057344637,
              4785696847444195453},
            __mask_was_saved = 0,
            __saved_mask = {
              __val =                 {0,
                0,
                0,
                0,
                0,
                17179871248,
                32,
                4294901760,
                0,
                72057594037927937,
                35936214102541,
                18446744073709551615,
                0,
                140678188960014,
                67108864,
                4294967295}
            }
          }}
        prepend_file_p = <optimized out>
        append_file_p = 0x0
        prepend_file = {
          type = ZEND_HANDLE_FILENAME,
          filename = 0x7ff23a1ab7c0 "/home/fedorenko/fedorenko.php",
          opened_path = 0x0,
          handle = {
            fd = 0,
            fp = 0x0,
            stream = {
              handle = 0x0,
              isatty = 0,
              mmap = {
                len = 0,
                pos = 0,
                map = 0x0,
                buf = 0x0,
                old_handle = 0x0,
                old_closer = 0x0
              },
              reader = 0x0,
              fsizer = 0x0,
              closer = 0x0
            }
          },
          free_filename = 0 '\000'
        }
        append_file = {
          type = ZEND_HANDLE_FILENAME,
          filename = 0x0,
          opened_path = 0x0,
          handle = {
            fd = 0,
            fp = 0x0,
            stream = {
              handle = 0x0,
              isatty = 0,
              mmap = {
                len = 0,
                pos = 0,
                map = 0x0,
                buf = 0x0,
                old_handle = 0x0,
                old_closer = 0x0
              },
              reader = 0x0,
              fsizer = 0x0,
              closer = 0x0
            }
          },
          free_filename = 0 '\000'
        }
        old_cwd = 0x7fff82e66290 "/"
        retval = 0
#8  0x00007ff234ad9272 in php_handler (r=<optimized out>) at /build/php5-gydbSc/php5-5.6.12+dfsg/sapi/apache2handler/sapi_apache2.c:667
        zfd = {
          type = ZEND_HANDLE_FILENAME,
          filename = 0x7ff238d65558 "/home/fedorenko/baza/www/index.php",
          opened_path = 0x0,
          handle = {
            fd = 927271182,
            fp = 0x7ff23745090e <fixup_redir+62 at mod_alias.c:489>,
            stream = {
              handle = 0x7ff23745090e <fixup_redir+62 at mod_alias.c:489>,
              isatty = 953571784,
              mmap = {
                len = 140678312384904,
                pos = 140678312383866,
                map = 0x7ff238d640a0,
                buf = 0x0,
                old_handle = 0x7ff238d640a0,
                old_closer = 0x7ff238fdb46d
              },
              reader = 0x2,
              fsizer = 0x7ff238d60028,
              closer = 0x7ff238d6a290
            }
          },
          free_filename = 0 '\000'
        }
        __orig_bailout = 0x0
        __bailout =           {{
            __jmpbuf =               {140678312370336,
              -4787787274844358531,
              140678312370336,
              140678317207584,
              140735389534060,
              140678312403600,
              4787705847467751549,
              4785696429574076541},
            __mask_was_saved = 0,
            __saved_mask = {
              __val =                 {140678313596472,
                140678313643480,
                140678312362368,
                1,
                140678313643480,
                140678312362416,
                0,
                140678317207584,
                140735389534060,
                140678312403600,
                140678258482339,
                140678314181544,
                3,
                140678312362416,
                140678312370336,
                140678313601848}
            }
          }}
        ctx = 0x7ff238d60208
        conf = <optimized out>
        brigade = 0x7ff238d60ce0
        bucket = <optimized out>
        rv = <optimized out>
        parent_req = 0x0
#9  0x00007ff238fb8fd0 in ap_run_handler (r=0x7ff238d620a0) at config.c:169
        pHook = 0x7ff238e8eb60
        n = 2
        rv = -94752768
#10 0x00007ff238fb9519 in ap_invoke_handler (r=r@entry=0x7ff238d620a0) at config.c:433
        handler = <optimized out>
        p = <optimized out>
        result = <optimized out>
        old_handler = 0x7ff238ea33f8 "application/x-httpd-php"
        ignore = <optimized out>
#11 0x00007ff238fcf7ba in ap_process_async_request (r=0x7ff238d620a0) at http_request.c:338
        access_status = 0
#12 0x00007ff238fcfa94 in ap_process_request (r=r@entry=0x7ff238d620a0) at http_request.c:373
        bb = <optimized out>
        b = <optimized out>
        c = 0x7ff238d6a290
        rv = <optimized out>
#13 0x00007ff238fcbdee in ap_process_http_sync_connection (c=0x7ff238d6a290) at http_core.c:210
        keep_alive_timeout = 5000000
        r = 0x7ff238d620a0
        cs = 0x0
        csd = 0x0
        mpm_state = 0
#14 ap_process_http_connection (c=0x7ff238d6a290) at http_core.c:251
No locals.
#15 0x00007ff238fc2b10 in ap_run_process_connection (c=0x7ff238d6a290) at connection.c:41
        pHook = 0x7ff238e891e8
        n = 0
        rv = -94752768
#16 0x00007ff238fc2f28 in ap_process_connection (c=c@entry=0x7ff238d6a290, csd=<optimized out>) at connection.c:213
        rc = <optimized out>
#17 0x00007ff2353ec767 in child_main (child_num_arg=child_num_arg@entry=2) at prefork.c:704
        current_conn = 0x7ff238d6a290
        csd = 0x7ff238d6a0a0
        thd = 0x7ff238d6c0a0
        osthd = 140678314276736
        ptrans = 0x7ff238d6a028
        allocator = 0x7ff23a55a260
        status = <optimized out>
        i = <optimized out>
        lr = <optimized out>
        pollset = 0x7ff238d6c158
        sbh = 0x7ff238d6c150
        bucket_alloc = 0x7ff238d66028
        last_poll_idx = 1
        lockfile = <optimized out>
#18 0x00007ff2353ec9a6 in make_child (s=0x7ff238f27f30, slot=2) at prefork.c:800
        pid = 0
#19 0x00007ff2353ed60e in perform_idle_server_maintenance (p=<optimized out>) at prefork.c:902
        i = <optimized out>
        idle_count = <optimized out>
        ws = <optimized out>
        free_length = <optimized out>
        free_slots =           {2,
          8,
          9,
          10,
          0 <repeats 28 times>}
        last_non_dead = <optimized out>
        total_non_dead = <optimized out>
#20 prefork_run (_pconf=<optimized out>, plog=<optimized out>, s=<optimized out>) at prefork.c:1090
        status = 11
        pid = {
          pid = -1,
          in = 0x7ff238fda460,
          out = 0xa,
          err = 0x7ff2386b6056
        }
        child_slot = <optimized out>
        exitwhy = (APR_PROC_SIGNAL | APR_PROC_SIGNAL_CORE)
        processed_status = <optimized out>
        index = <optimized out>
        remaining_children_to_start = 0
        rv = <optimized out>
#21 0x00007ff238f9ef0e in ap_run_mpm (pconf=0x7ff238f54028, plog=0x7ff238f21028, s=0x7ff238f27f30) at mpm_common.c:94
        pHook = 0x7ff238e89700
        n = 0
        rv = -94752768
#22 0x00007ff238f986c6 in main (argc=3, argv=0x7fff82e68c18) at main.c:777
        c = 0 '\000'
        showcompile = 0
        showdirectives = 0
        confname = 0x7ff238fd9a22 "apache2.conf"
        def_server_root = 0x7ff238fd9a15 "/etc/apache2"
        temp_error_log = 0x0
        error = <optimized out>
        process = 0x7ff238f56118
        pconf = 0x7ff238f54028
        plog = 0x7ff238f21028
        ptemp = 0x7ff238f23028
        pcommands = 0x7ff238f2b028
        opt = 0x7ff238f2b118
        rv = <optimized out>
        mod = 0x7ff2391fc160 <ap_prelinked_modules+64>
        opt_arg = 0x7ff238f56028 "(\240\365\070\362\177"
        signal_server = <optimized out>
(gdb) frame 2
#2  0x00007ff234a2231b in dtrace_execute_internal (execute_data_ptr=<optimized out>, fci=<optimized out>, return_value_used=<optimized out>)
    at /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_dtrace.c:97
97  /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_dtrace.c: No such file or directory.
(gdb) l
92  in /build/php5-gydbSc/php5-5.6.12+dfsg/Zend/zend_dtrace.c
(gdb) printzv arg
No symbol "arg" in current context.
(gdb) zbacktrace
[0x7fff82e65f50] Exception->__toString()
(gdb)

from mongo-php-library.

bjori avatar bjori commented on July 1, 2024

Thats very different backtrace. Still nothing related to mongodb though.
This shows a segfault while invoking the __toString() method on the Exception object.

Can you match that to your fedorenko.php ?
This looks like something that should probably be reported to php.net

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Can you match that to your fedorenko.php ?

I removed prepend file, it doesnt affect issue.

This looks like something that should probably be reported to php.net

Sorry but problem is on your side :)

Here is what I got. MongoDB\Driver\Manager (class from mongodb.so?) some time throws exceptions, and that exceptions are broken. Looks like some there deep in mongodb.so is wrong exceptions initialization.

How I got is:

  • Open vendor/mongodb/mongodb/src/Collection.php
  • Find method findOne.
  • Replace
$cursor = $this->manager->executeQuery($this->ns, $query, $this->rp);

by

try {
    $cursor = $this->manager->executeQuery($this->ns, $query, $this->rp);
} catch (\Exception $e) {
    echo '<pre>';
    var_dump($e->getTraceAsString(), $e->getMessage());
}
  • Decrase limits of MongoDB\Client in test case to minimal:
$options = ['w' => 1, 'journal' => 0, 'connectTimeoutMS' => 1, 'socketTimeoutMS' => 1, 'wTimeoutMS' => 1];

$clients = [
    new \MongoClient($host, $options),
    new MongoDB\Client($host, $options),
];
  • Run test case several times.

The result is:

string(265) "#0 /home/fedorenko/baza/vendor/mongodb/mongodb/src/Collection.php(531): MongoDB\Driver\Manager->executeQuery('goods_archive.g...', Object(MongoDB\Driver\Query), NULL)
#1 /home/fedorenko/baza/www/index.php(27): MongoDB\Collection->findOne(Object(stdClass))
#2 {main}"
string(57) "Failed to read 4 bytes from socket within 1 milliseconds."

Where is no seg faults!

And if I rollback try|catch from vendor/mongodb/mongodb/src/Collection.php seg faults returns :)

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: Thanks for following up. I intend to look through the new posts later today. But I always wanted to address:

  1. MongoDB\Collection has no method to set read preference, we cant use constructor instead because of our private factory. Old MongoClient had setReadPreference, can you return it?

@bjori already explained by we're keeping the library objects immutable, but there are plans to introduce withWriteConcern() and withReadPreference() methods that return a new instance of the Collection or Database object with the appropriate change applied. This is being tracked in PHPLIB-49.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

@jmikola: Thank you, setReadPreference is not critical problem. We can rewrite our client code to support both Mongo implementations.

Seg faults after connection or read time out blocking us from migration to new mongodb and PHP 7 in future.

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: I continue to have trouble reproducing your segfault. I'm attempting to reproduce it with the code in this gist. For context, I'm using:

  • https://pecl.php.net/package/mongodb/1.0.0alpha2
  • mongobridge is a basic utility to delay network traffic (otherwise my local mongod easily responses to everything within 1ms)
  • I'm disabling my PHP INI and only loading the mongodb.so extension. The script prints all loaded extensions, so I see anything compiled into PHP itself, plus mongodb.so, which I'm loading.

Can you attempt to reproduce with that script? Since your mongod is remote, you shouldn't need mongobridge.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

@jmikola: check out my new test case.

I combine two mongodb usage methods - native via extension (section A) and via pear packet (section B). I cant reproduce seg faults when using native code. All works find.
But, then I use pear packet seg faults are happens. Can you try play with pear code calls?

Another strange thing I got -- all data in both cases are same. I made var_dump of Manger, Query and NS before native and pear queries and whey are same:
https://www.dropbox.com/s/76dn6is9jvaci44/Screenshot%202015-09-04%2017.51.03.png?dl=0
https://www.dropbox.com/s/49yjtkq0mxi756o/Screenshot%202015-09-04%2017.51.14.png?dl=0

WTH?! Pear code changes some internal state of extension and I cant see changes through var_dump? Extension fails only inside PHP name spaces?

Of course I can debug pear code step by step to search dependences of code calls and seg faults, but this will take some time... Have you any ideas how I can help you to reproduce bug?

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

New way to reproduce problem with part of code from pear packet.

Create php.ini file in folder, write where one line:

extension=mongodb.so

Make index.php file with this content:

<?php
namespace MongoDB;

use MongoDB\Driver\Cursor;
use MongoDB\Driver\Manager;
use MongoDB\Driver\Query;

class CollectionEx
{
    public function findOne($manager)
    {
        $options = ['sort' => array(), 'connectTimeoutMS' => 1, 'socketTimeoutMS' => 1, 'wTimeoutMS' => 1];
        $filter = [];
        $query = $this->_buildQuery($filter, $options);
        $manager->executeQuery('JOPA', $query);
    }

    protected function _buildQuery($filter, $options)
    {
        $options["cursorFlags"] = 0;
        $query = new Query($filter, $options);

        return $query;
    }
}

$host = 'mongodb://aux.srv.loc:27018';
$options = ['w' => 1, 'journal' => 0, 'connectTimeoutMS' => 1, 'socketTimeoutMS' => 1, 'wTimeoutMS' => 1];
$manager = new Manager($host, $options);

$collection = new CollectionEx($manager);
$collection->findOne($manager);

Execute file from shell like this:

fedorenko@vm ~/baza $ php -c ~/baza/ www/index.php

Write your own folder path in "-c" parameter.

Result of this test case for me will be:

fedorenko@vm ~/baza $ php -c ~/baza/ www/index.php
Segmentation fault

Can you please check new test case and confirm issue?

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

By the way, can I make and test latest mongodb from source code?

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

Check out my new test case: https://gist.github.com/jmikola/37b2fb5954d790b3b416
I combine two mongodb usage methods - native via extension (section A) and via pear packet (section B). I cant reproduce seg faults when using native code. All works find. But, then I use pear packet seg faults are happens. Can you try play with pear code calls?

@dmifedorenko: The gist you linked is the same that I previously shared. Did you mean to paste another link?

Perhaps related to that, I don't know what "native via extension (section A) and via pear packet (section B)" are referring to. By "pear packet", do you mean the PECL package for 1.0.0-alpha2?

By the way, can I make and test latest mongodb from source code?

If you're referring to mongo-php-driver-prototype, you can definitely clone that, initialize the git submodules for libmongoc and libbson, and compile it from scratch with the following:

phpize && ./configure --enable-developer-flags && make clean && make -j 5 all && make install

I will look into the new test case you supplied in the last comment.

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: running your last test case, I am able to reproduce a segfault and two different exceptions. See: https://gist.github.com/jmikola/200cb049598ce9f9b766. I ended up removing the class and namespace, as those did not seem to be contributing factors.

These results were obtained with both the latest PECL package (1.0.0alpha2) and a fresh build of the master branch. Based on the exceptions, it seems as if the $options passed to a Query constructor may be getting inappropriately modified by the extension. In any event, this gives me a point of reproduction that I can move on from.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

In any event, this gives me a point of reproduction that I can move on from.

Great news, thank you! Will wait for fix.

This issue blocks me from migration on new MongoDb extension and PHP7.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Upgraded to beta1, still has seg faults.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

Any news about issue?

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: I've not investigated the issues further, but these are a priority for publishing a stable 1.0.0 release:

I do not expect these to be resolved in the next beta release; however, the issues above are being scheduled in our development sprints if you wish to keep abreast of them.

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: FYI: PHPC-430 should now be resolved via mongodb/mongo-php-driver#117.

from mongo-php-library.

dmifedorenko avatar dmifedorenko commented on July 1, 2024

@jmikola confirm. Bug is fixed.

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: Good to hear. PHPC-430 should appear in the next beta release of the extension. I'm going to close out this GitHub issue.

As for PHPC-403, we can just track that in the JIRA ticket.

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

@dmifedorenko: FYI, I've been unable to reproduce PHPC-430 and have resolved it as such. If you're still able to reproduce the original failure, please follow up in the ticket with a modified version of the script I shared there (updated a bit based on recent PHPLIB changes). Thanks.

from mongo-php-library.

ziyaindia avatar ziyaindia commented on July 1, 2024

What is the alternative for Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Cursor::hasNext?

One of my application using MongoDB Client library with old php version. I just upgraded my php version as well as upgraded mongo library. When following function is calling, it's giving me

Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Cursor::hasNext

`function get_result_row () {

        if ($this->cursor->hasNext()) {
            return $this->cursor->getNext();
        }

}`

Please suggest how i can fix it?

from mongo-php-library.

jmikola avatar jmikola commented on July 1, 2024

Cross-referencing the comment above with #703.

from mongo-php-library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.