Azure / azure-sdk-for-python

This repository is for active development of the Azure SDK for Python. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/python/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-python.
MIT License
4.63k stars 2.84k forks source link

Unable to receive ServiceBus queue message created in Java SDK #15568

Closed pfijalki closed 3 years ago

pfijalki commented 3 years ago

Describe the bug Cannot receive message sent from Java (OpenJDK 1.8) Azure servicebus SDK

To Reproduce Steps to reproduce the behavior:

  1. Send message through java using https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-java-how-to-use-queues
  2. Try to receive message using https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-python-how-to-use-queues

Expected behavior Possibility to process the message

Attempt on receiving message results in SIGSEGV and python crash

*** SIGSEGV (@0x0) received by PID 20726 (TID 0x7fceb26c7080) from PID 0; stack trace: ***
    @     0x7fceb22be8a0 (unknown)
    @     0x7fceb18a4811 (unknown)
    @     0x5615294d604c PyBytes_FromString
    @     0x7fceaa2ce6ac __pyx_pf_5uamqp_7c_uamqp_11cProperties_7user_id___get__
    @     0x7fceaa2ce5ee __pyx_pw_5uamqp_7c_uamqp_11cProperties_7user_id_1__get__
    @     0x7fceaa306c8f __pyx_getprop_5uamqp_7c_uamqp_11cProperties_user_id
    @     0x561529526fb7 PyObject_GenericGetAttr
    @     0x5615294c311c _PyEval_EvalFrameDefault
    @     0x561529598d20 _PyEval_EvalCodeWithName
    @     0x5615294dc08a _PyFunction_FastCallDict
    @     0x5615294df231 _PyObject_Call_Prepend
    @     0x5615295463b1 slot_tp_init
    @     0x56152953fb37 type_call
    @     0x5615294dc82f _PyObject_FastCallKeywords
    @     0x5615294c36f6 _PyEval_EvalFrameDefault
    @     0x5615294bf827 function_code_fastcall
    @     0x5615294c729d _PyEval_EvalFrameDefault
    @     0x5615294bf827 function_code_fastcall
    @     0x5615294dc1f7 _PyFunction_FastCallDict
    @     0x5615296756d5 property_descr_get
    @     0x561529526fb7 PyObject_GenericGetAttr
    @     0x5615294c311c _PyEval_EvalFrameDefault
    @     0x561529598d20 _PyEval_EvalCodeWithName
    @     0x5615294dc29f _PyFunction_FastCallKeywords
    @     0x5615294c7da1 _PyEval_EvalFrameDefault
    @     0x561529598d20 _PyEval_EvalCodeWithName
    @     0x5615294dc08a _PyFunction_FastCallDict
    @     0x5615294df231 _PyObject_Call_Prepend
    @     0x5615295463b1 slot_tp_init
    @     0x56152953fb37 type_call
    @     0x5615294dc82f _PyObject_FastCallKeywords
    @     0x5615294c36f6 _PyEval_EvalFrameDefault
yunhaoling commented 3 years ago

hey @pfijalki, thanks for reaching out.

I followed your steps and was able to reproduce the issue. This should be a bug triggered by the underlying uamqp library reading "inaccessible memory" on property of a message, I have created issue in the uamqp repo: https://github.com/Azure/azure-uamqp-python/issues/186.

I'll investigate on how to fix it and then include the fix in uamqp bug fix release.

pfijalki commented 3 years ago

hey @yunhaoling, thank you for the update and fast response Time. Do you mind sharing in brief description steps to debug/reproduce such issue ? I tried to do this by myself but couldn't asses which line was causing the error

yunhaoling commented 3 years ago

hello @pfijalki ,

This one is a bit hard to reproduce as it turns out to be a bug in the cython layer. if you're interested in the detail, I already got a PR out to fix the issue: https://github.com/Azure/azure-uamqp-python/pull/187

the main issue here is trying to access the user_id of an AMQP message in the "src/properties.pyx":

    def user_id(self):
        cdef c_amqpvalue.amqp_binary _binary
        if c_amqp_definitions.properties_get_user_id(self._c_value, &_binary) == 0:
            return <char*>_binary.bytes

return <char*>_binary.bytes where _binary.bytes could be a NULL C pointer, and in this case it shouldn't be returned directly which is the receiving messages sent by Java SDK case.

To fix it, we need to convert the C char* data to a python variable first by

bytes_value = <char*>_binary.bytes

then we could safely return bytes_value

yunhaoling commented 3 years ago

hey @pfijalki , FYI: my fix PR gets merged, we'll do a uamqp release after we address some other uamqp issues.

yunhaoling commented 3 years ago

hello @pfijalki , hope you're keeping well.

We have released uamqp v1.2.13 today which includes the fix. Please upgrade to the latest uamqp version via pip install uamqp --upgrade to see if it solves the problem.

I'm closing this issue now, but feel free to reopen if you still get trouble with the latest version.