Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when pickle ServiceBusReceivedMessage object #27947

Closed
IsmaelJS opened this issue Dec 14, 2022 · 10 comments
Closed

error when pickle ServiceBusReceivedMessage object #27947

IsmaelJS opened this issue Dec 14, 2022 · 10 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. Messaging Messaging crew question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus

Comments

@IsmaelJS
Copy link

IsmaelJS commented Dec 14, 2022

  • Package Name: azure-servicebus
  • Package Version: 7.8.1
  • Operating System: alpine 3.12
  • Python Version: 3.8.6

Describe the bug
There is an error when trying to pickle the ServiceBusReceivedMessage object.
The "prefork" pool (multiprocessing) in celery uses pickle for serialization, and from v5.2 it is not working, see details in celery/celery#7237

To Reproduce
It can be reproduced by using the following code:

import os
import json
import pickle
from azure.servicebus import ServiceBusClient, ServiceBusMessage

CONNECTION_STR = "XXX"
QUEUE_NAME = "XXX"

msg = {
   "body":"W1tdLCB7ImlucHV0X2lkIjogNH0sIHsiY2FsbGJhY2tzIjogbnVsbCwgImVycmJhY2tzIjogbnVsbCwgImNoYWluIjogbnVsbCwgImNob3JkIjogbnVsbH1d",
   "content-encoding":"utf-8",
   "content-type":"application/json",
   "headers":{
      "lang":"py",
      "task":"tasks.example_task",
      "id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
      "shadow":None,
      "eta":"2021-10-07T02:30:23.764066+00:00",
      "expires":None,
      "group":None,
      "group_index":None,
      "retries":1,
      "timelimit":[
         None,
         None
      ],
      "root_id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
      "parent_id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
      "argsrepr":"()",
      "kwargsrepr":"{'input_id': 4}",
      "origin":"gen36@94713e01a9c0",
      "ignore_result":1,
      "x_correlator":"44a1978d-c869-4173-afe4-da741f0edfb9"
   },
   "properties":{
      "correlation_id":"7c66557d-e4bc-437f-b021-b66dcc39dfdf",
      "reply_to":"7b9a3672-2fed-3e9b-8bfd-23ae2397d9ad",
      "origin":"gen68@c33d4eef123a",
      "delivery_mode":2,
      "delivery_info":{
         "exchange":"",
         "routing_key":"celery_task_queue"
      },
      "priority":0,
      "body_encoding":"base64",
      "delivery_tag":"dc83ddb6-8cdc-4413-b88a-06c56cbde90d"
   }
}

servicebus_client = ServiceBusClient.from_connection_string(conn_str="XXX")

with servicebus_client:
    with servicebus_client.get_queue_sender(QUEUE_NAME) as sender:
        # Sending a single message
        single_message = ServiceBusMessage(json.dumps(msg))
        sender.send_messages(single_message)


with servicebus_client:
    receiver = servicebus_client.get_queue_receiver(queue_name=QUEUE_NAME)
    with receiver:
        received_msgs = receiver.receive_messages(max_message_count=10, max_wait_time=5)
        for msg in received_msgs:
            print(str(msg))
            pickle.dumps(msg)
            receiver.complete_message(msg)

print("Receive is done.")


The result is:

Traceback (most recent call last):
  File "test_pickle.py", line 40, in <module>
    pickle.dumps(msg)
  File "stringsource", line 2, in uamqp.c_uamqp.CompositeValue.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

Expected behavior
It should works.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
There are several bugs opened in celery and billiard which might be related to this issue:
celery/celery#7237
celery/billiard#356

@ghost ghost added customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Dec 14, 2022
@github-actions github-actions bot added the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Dec 14, 2022
@kashifkhan
Copy link
Member

Thank you the feedback @IsmaelJS. We will investigate and get back to you asap

@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Dec 14, 2022
@kashifkhan kashifkhan added Service Bus needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. labels Dec 14, 2022
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Dec 14, 2022
@swathipil
Copy link
Member

Hi @IsmaelJS - I've just tried running the provided sample and am not seeing this error. We've had pickling issues in the past due to some objects in the underlying uamqp library being incompatible. This has been fixed in uamqp>=1.3.0.

Would you be able to provide the uamqp package version that you're using? Thanks!

@kashifkhan kashifkhan added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Dec 14, 2022
@IsmaelJS
Copy link
Author

IsmaelJS commented Dec 15, 2022

Hi @swathipil , I have updated the serialization error because the old one corresponds to azure-servicebus==7.9.0a1.

The error raised is the following:

Traceback (most recent call last):
  File "test_pickle.py", line 40, in <module>
    pickle.dumps(msg)
  File "stringsource", line 2, in uamqp.c_uamqp.CompositeValue.__reduce_cython__
TypeError: no default __reduce__ due to non-trivial __cinit__

The lib version are:

azure-servicebus==7.8.1
uamqp==1.6.3

Thank you so much.

@ghost ghost added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Dec 15, 2022
@swathipil
Copy link
Member

swathipil commented Dec 15, 2022

Hi @IsmaelJS - Can you provide an example of data sent here that results in this error?

I believe I'm not able to reproduce using this sample b/c the data I'm sending and receiving doesn't result in the creation of the uamqp.c_uamqp.CompositeValue object and is therefore picklable.

@IsmaelJS
Copy link
Author

Hi @swathipil , I have updated the code within "To Reproduce" section with the data used.
Thank you so much.

@suranshu-engg-segg
Copy link

is there any update about it ?

@swathipil
Copy link
Member

Hi @IsmaelJS - Thanks for the update and your patience! We were able to reproduce this issue.

Releasing uamqp with the bug fix for this will take some time. However, we are currently directing our efforts toward moving azure-servicebus away from uamqp and to an internal Pure Python-based AMQP stack. Pickling should no longer be an issue once we've released this Pure Python-based azure-servicebus. We plan to release a beta of this in the upcoming month and are working steadily towards a stable release.

We will keep you updated as we move forward!

@kashifkhan
Copy link
Member

Hi @IsmaelJS , @suranshu-engg-segg we will be releasing a new version of the service bus client this week that uses the pure python based AMQP library which should address the pickling issues. Ill update this issue once its on pypi

@swathipil
Copy link
Member

Hi @IsmaelJS, @suranshu-engg-segg - We just released azure-servicebus 7.10.0, which includes the fix for pickling ServiceBusReceivedMessage. https://pypi.org/project/azure-servicebus/7.10.0/

Thanks!

@swathipil swathipil added the issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. label May 9, 2023
@github-actions github-actions bot removed the needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team label May 9, 2023
@github-actions
Copy link

github-actions bot commented May 9, 2023

Hi @IsmaelJS. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed Workflow: The Azure SDK team believes it to be addressed and ready to close. Messaging Messaging crew question The issue doesn't require a change to the product in order to be resolved. Most issues start as that Service Bus
Projects
None yet
Development

No branches or pull requests

4 participants