perl-Couchbase-Client icon indicating copy to clipboard operation
perl-Couchbase-Client copied to clipboard

Tests fail with "perl: xs/opcontext.c:73: plcb_opctx_initop: Assertion"

Open bigunyak opened this issue 8 years ago • 11 comments

Hi there,

I'm trying to install the module but the tests fail with the following error:

Couchbase-2.0.3-ScCY26 $ make test
Running Mkbootstrap for Couchbase ()
chmod 644 Couchbase.bs
PERL_DL_NONLAZY=1 /opt/perlbrew/perls/perl-5.20.2/bin/perl "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-load.t .. ok   
t/01-main.t .. #[WARN] MockServer.pm:112 (Couchbase::MockServer::_do_run): Executing java -jar /home/dima/.cpan/build/Couchbase-2.0.3-ScCY26/t/tmp/CouchbaseMock.jar --buckets=default::couchbase --port=0 --nodes=5 --harakiri-monitor=localhost:34953
perl: xs/opcontext.c:73: plcb_opctx_initop: Assertion `((svtype)((_svstash)->sv_flags & 0xff)) >= SVt_PVMG' failed.
t/01-main.t .. No subtests run 

Test Summary Report
-------------------
t/01-main.t (Wstat: 6 Tests: 0 Failed: 0)
  Non-zero wait status: 6
  Parse errors: No plan found in TAP output
Files=2, Tests=3,  1 wallclock secs ( 0.05 usr  0.00 sys +  0.31 cusr  0.01 csys =  0.37 CPU)
Result: FAIL
Failed 1/2 test programs. 0/3 subtests failed.
Makefile:1118: recipe for target 'test_dynamic' failed
make: *** [test_dynamic] Error 255

I have libcouchbase-2.5.8 C client library installed. The CouchbaseMock.jar file was taken from libcouchbase-2.5.8/tests/CouchbaseMock.jar.

bigunyak avatar May 12 '16 08:05 bigunyak

If you're not going to support the module, maybe you can at lest specify what should be the C client library version this module works with...?

bigunyak avatar May 13 '16 15:05 bigunyak

I haven't had time to look into it, but you can likely safely skip the tests. The C client version is backwards compatible and should therefore function perfectly fine with the library. The problem seems to be with the Perl version and a change in the XS behavior. Specifically, https://github.com/mnunberg/perl-Couchbase-Client/blob/master/xs/plcb-return.h#L7 - apparently, sv_isobject is no longer sufficient to assume that an SV actually has a stash.

Maybe you can try regenerating ppport.h, or simply change those macros to always use sv_derived_from until I can figure out why it's broken.

mnunberg avatar May 13 '16 16:05 mnunberg

Hmm, strange but the module works on my other machine which is Debian. Here is what I did on my Gentoo box:

  • Installed the latest C client library (libcouchbase-2.5.8) as it's described here: http://developer.couchbase.com/documentation/server/4.1/sdks/c-2.4/download-install.html under "Installing from source" section.
  • Tried to install Couchbase perl client through CPAN client but tests fail with the error I posted in the report here.
  • I manually install the client but it fails on the first attempt to call $cb->upsert($doc) with the same error:
perl: xs/opcontext.c:73: plcb_opctx_initop: Assertion `((svtype)((_svstash)->sv_flags & 0xff)) >= SVt_PVMG' failed.
  • I should note that the latest Python client installed through pip works fine on the same Gentoo box.

On the Debian machine:

  • I installed C client library from the Debian repository.
  • Perl client through CPAN again.
  • Python client through pip.
  • And everything works fine.

So, now I'm confused, what could be wrong on my Gentoo machine?

bigunyak avatar May 13 '16 18:05 bigunyak

I have perl v5.14.2 on the Debian box and perl v5.20.2 on the Gentoo machine.

bigunyak avatar May 13 '16 18:05 bigunyak

I should have been a bit clearer. I think this has to do with the version of Perl rather than the version of the Couchbase library. It seems that Perl changed some of the XS internals and XS behavior breaking older code.

It might also be the case that the ppport.h file is too old, and that the assertion of SVt_PVMG is no longer true. Can you apply the fix I mentioned to the Gentoo version and see if this works? if so, I might just need to generate a new ppport.h

On May 13, 2016, at 11:03 AM, Dmitry Bigunyak [email protected] wrote:

Hmm, strange but the module works on my other machine which is Debian. Here is what I did on my Gentoo box:

Installed the latest C client library (libcouchbase-2.5.8) as it's described here: http://developer.couchbase.com/documentation/server/4.1/sdks/c-2.4/download-install.html http://developer.couchbase.com/documentation/server/4.1/sdks/c-2.4/download-install.html under "Installing from source" section. Tried to install Couchbase perl client through CPAN client but tests fail with the error I posted in the report here. I manually install the client but it fails on the first attempt to call $cb->upsert($doc) with the same error: perl: xs/opcontext.c:73: plcb_opctx_initop: Assertion `((svtype)((_svstash)->sv_flags & 0xff)) >= SVt_PVMG' failed. I should note that the latest Python client installed through pip works fine on the same Gentoo box. On the Debian machine:

I installed C client library from the Debian repository. Perl client through CPAN again. Python client through pip. And everything works fine. So, now I'm confused, what could be wrong on my Gentoo machine?

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/mnunberg/perl-Couchbase-Client/issues/44#issuecomment-219116606

mnunberg avatar May 13 '16 18:05 mnunberg

I regenerated new ppport.h file with

perl -MDevel::PPPort -e 'Devel::PPPort::WriteFile()'

and then replace xs/ppport.h with the new file but that didn't help, still the same error. I didn't quite get what you meant by:

or simply change those macros to always use sv_derived_from until I can figure out why it's broken.

bigunyak avatar May 13 '16 19:05 bigunyak

Callpath:

  • https://github.com/mnunberg/perl-Couchbase-Client/blob/master/xs/opcontext.c#L73
  • https://github.com/mnunberg/perl-Couchbase-Client/blob/master/xs/plcb-return.h#L6

Likely the definition of SvSTASH is causing this assertion error. Because the sv_isobject(sv) && SvSTASH(sv) == ... is just an optimization, you can just modify those macros to expand to a simple sv_derived_from

mnunberg avatar May 13 '16 19:05 mnunberg

Sorry for the long reply. Finally tried what you suggested, modified macros in the xs/plcb-return.h file as follows:

#define plcb_doc_isa(obj, ret) \
    (sv_derived_from(ret, PLCB_RET_CLASSNAME))

#define plcb_opctx_isa(obj, ret) \
    (sv_derived_from(ret, PLCB_OPCTX_CLASSNAME))

The result of this is that tests don't fail now, but there is this strange output:

Couchbase-2.0.3-MUxDiC $ make test
PERL_DL_NONLAZY=1 /opt/perlbrew/perls/perl-5.20.2/bin/perl "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00-load.t .. ok   
t/01-main.t .. #[WARN] MockServer.pm:112 (Couchbase::MockServer::_do_run): Executing java -jar /home/userx/.cpan/build/Couchbase-2.0.3-MUxDiC/t/tmp/CouchbaseMock.jar --buckets=default::couchbase --port=0 --nodes=5 --harakiri-monitor=localhost:36368
t/01-main.t .. 79/? Couldn't schedule operation. Code 0x1b (Client not bootstrapped. Ensure bootstrap/connect was attempted and was successful)
t/01-main.t .. 98/? Registering name '/default/_design/blog/_view/recent_posts'
Use of uninitialized value $viewspec in pattern match (m//) at /home/userx/.cpan/build/Couchbase-2.0.3-MUxDiC/blib/lib/Couchbase/View/Handle.pm line 40.
java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
        at sun.nio.ch.IOUtil.read(IOUtil.java:197)
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:384)
        at sun.nio.ch.SocketAdaptor$SocketInputStream.read(SocketAdaptor.java:203)
        at sun.nio.ch.ChannelInputStream.read(ChannelInputStream.java:103)
        at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:139)
        at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:155)
        at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:284)
        at org.apache.http.impl.io.DefaultHttpRequestParser.parseHead(DefaultHttpRequestParser.java:131)
        at org.apache.http.impl.io.DefaultHttpRequestParser.parseHead(DefaultHttpRequestParser.java:54)
        at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
        at org.apache.http.impl.DefaultBHttpServerConnection.receiveRequestHeader(DefaultBHttpServerConnection.java:132)
        at org.apache.http.protocol.HttpService.handleRequest(HttpService.java:307)
        at org.couchbase.mock.httpio.HttpServer$Worker.doReadLoop(HttpServer.java:173)
        at org.couchbase.mock.httpio.HttpServer$Worker.run(HttpServer.java:194)
Registering name '/default/_design/tv06/_view/tv06'
t/01-main.t .. 134/? Registering name '/default/_design/blog/_view/recent-posts'
t/01-main.t .. ok     
All tests successful.
Files=2, Tests=142,  5 wallclock secs ( 0.08 usr  0.00 sys +  3.79 cusr  0.11 csys =  3.98 CPU)
Result: PASS

The good news is that the module works now! :)

bigunyak avatar May 18 '16 10:05 bigunyak

Hi there,

Just curious if you're planning on fixing this problem in a new version any time soon? And maybe a more general question: are you going to support this module in any form in the future?

bigunyak avatar May 26 '16 15:05 bigunyak

I would like to support this module, however I'm not sure how much time I have on my hands. In principle I'd like to continue supporting this module on major platforms, which in this case means the platforms I actually use. I would not mind integrating patches to other perl versions, but I likely will not have the time to ensure it works on all Perl versions except the one I may have installed locally (in this case, 5.16 and 5.18).

Also consider that I no longer use Perl on a day-to-day basis here at Couchbase, so my interest in this module is a bit lower than it once was (where I actually needed this module to function). Of course, if enough people showed interest in the Perl module, it might become an officially supported module. Right now it's supported in my free time and not a corporate Couchbase endeavor.

To properly integrate this fix into a newer version I would need to check whether this fix actually works as intended, or if it's simply a small band-aid that has other adverse consequences.

mnunberg avatar May 26 '16 15:05 mnunberg

I was also asking about official Perl client support on the Couchbase Forums site, unfortunately no plans for it right now. I guess only if Couchbase grows big enough and more people from the Perl community show up their interest in the product, maybe then... Anyways, thanks for your responses and your work at your "free time". :+1:

bigunyak avatar May 26 '16 15:05 bigunyak