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

[Service Bus] Precision is lost on the messageId when a number is passed #1098

Closed
ramya-rao-a opened this issue Feb 3, 2019 · 5 comments
Closed
Assignees
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Service Bus

Comments

@ramya-rao-a
Copy link
Contributor

  • Send a message with messageId as say 1.15
  • Peek the queue or receive a message and check its id. It will be 1 instead of 1.15
@ramya-rao-a ramya-rao-a added bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Service Bus labels Feb 3, 2019
@ramya-rao-a ramya-rao-a changed the title [Service Bus] Messages sent with message id as a number are getting the ids rounded up [Service Bus] Precision is lost on the messageId when a number is passed Feb 3, 2019
@ramya0820 ramya0820 self-assigned this Feb 14, 2019
@ramya0820
Copy link
Member

ramya0820 commented Feb 17, 2019

Update on this issue from yesterday:

messageId is being wrapped at - https://github.com/amqp/rhea/blob/3ef54378e67bd63be6f057d9b74132ae18d0abac/lib/types.js#L481

On updating this to wrap it as double/float value, we are receiving rejection/error event from Service Bus.
(Following is updated log extract, including encoded data being successfully sent over rhea)

2019-02-16T23:57:28.616Z azure:service-bus:sender [connection-1] Sender 'unpartitioned-queue-f0561022-b438-b648-976d-862774585250', sending message: { body:
   Section {
     typecode: 117,
     content: <Buffer 31 2e 33 35>,
     multiple: undefined },
  message_annotations: {},
  subject: '1.25',
  message_id: 1.15 }
2019-02-16T23:57:28.617Z rhea:message Encoding section 1 of 4: Typed { type: TypeDesc { name: 'List0', typecode: 69, width: 0, category: 1, create: { [Function] typecode: 69 } }, value: [], descriptor: Typed { type: TypeDesc { name: 'SmallUlong', typecode: 83, width: 1, category: 1, read: [Function: read], write: [Function: write], create: [Function] }, value: 112 } }
2019-02-16T23:57:28.618Z rhea:message Encoding section 2 of 4: Typed { type: TypeDesc { name: 'Map32', typecode: 209, width: 4, category: 3, create: { [Function] typecode: 209 } }, value: [], descriptor: Typed { type: TypeDesc { name: 'SmallUlong', typecode: 83, width: 1, category: 1, read: [Function: read], write: [Function: write], create: [Function] }, value: 114 } }
2019-02-16T23:57:28.618Z rhea:message Encoding section 3 of 4: Typed { type: TypeDesc { name: 'List32', typecode: 208, width: 4, category: 3, create: { [Function] typecode: 208 } }, value: [ Typed { type: [TypeDesc], value: 1.15 }, <2 empty items>, Typed { type: [TypeDesc], value: '1.25' } ], descriptor: Typed { type: TypeDesc { name: 'SmallUlong', typecode: 83, width: 1, category: 1, read: [Function: read], write: [Function: write], create: [Function] }, value: 115 } }
2019-02-16T23:57:28.619Z rhea:message Encoding section 4 of 4: Typed { type: TypeDesc { name: 'Vbin8', typecode: 160, width: 1, category: 2, create: { [Function] typecode: 160 } }, value: <Buffer 31 2e 33 35>, descriptor: Typed { type: TypeDesc { name: 'SmallUlong', typecode: 83, width: 1, category: 1, read: [Function: read], write: [Function: write], create: [Function] }, value: 117 } }
2019-02-16T23:57:28.620Z rhea:message encoded 54 bytes
2019-02-16T23:57:28.620Z azure:service-bus:sender [connection-1] Sender 'unpartitioned-queue-f0561022-b438-b648-976d-862774585250', sent message with delivery id: 0
2019-02-16T23:57:28.622Z rhea:frames [connection-1]:1 -> transfer#14 {"delivery_tag":{"type":"Buffer","data":[48]}} <Buffer 00 53 70 45 00 53 72 d1 00 00 00 04 00 00 00 00 00 53 73 d0 00 00 00 15 00 00 00 04 82 3f f2 66 66 66 66 66 66 40 40 a1 04 31 2e 32 35 00 53 75 a0 04 ... >
2019-02-16T23:57:28.624Z rhea:raw [connection-1] SENT: 82 0000005202000001005314d00000000c000000064343a0013043424200537045005372d10000000400000000005373d00000001500000004823ff26666666666664040a104312e3235005375a004312e3335
2019-02-16T23:57:28.643Z rhea:io [connection-1] read 66 bytes
2019-02-16T23:57:28.643Z rhea:io [connection-1] got frame of size 66
2019-02-16T23:57:28.643Z rhea:raw [connection-1] RECV: 66 0000004202000001005315c0350641434041005325c02a0100531dc02403a311616d71703a6465636f64652d6572726f72a10d53797374656d2e446f75626c654040
2019-02-16T23:57:28.643Z rhea:frames [connection-1]:1 <- disposition#15 {"role":true,"settled":true,"state":[["amqp:decode-error","System.Double",null]]} 
2019-02-16T23:57:28.644Z rhea:events [connection-1] Received disposition for outgoing transfers
2019-02-16T23:57:28.644Z rhea:events [connection-1] Link got event: rejected
2019-02-16T23:57:28.644Z rhea-promise:sender [connection-1] sender got event: 'rejected'. Re-emitting the translated context.
2019-02-16T23:57:28.644Z rhea-promise:translate [connection-1] Translating the context for event: 'rejected'.
2019-02-16T23:57:28.645Z azure:service-bus:error [connection-1] Sender 'unpartitioned-queue-f0561022-b438-b648-976d-862774585250', got event rejected.
2019-02-16T23:57:28.674Z azure:service-bus:error DecodeError: System.Double
    at Object.translate (c:\workspace\newrepo3\azure-sdk-for-js\packages\@azure\servicebus\data-plane\node_modules\@azure\amqp-common\lib\errors.ts:537:13)
    at Sender.onRejected (c:\workspace\newrepo3\azure-sdk-for-js\packages\@azure\servicebus\data-plane\lib\core\messageSender.ts:521:25)
    at Sender.emit (events.js:182:13)
    at Sender.EventEmitter.emit (domain.js:441:20)
    at emit (c:\workspace\newrepo3\azure-sdk-for-js\packages\@azure\servicebus\data-plane\node_modules\rhea-promise\lib\util\utils.ts:183:20)
    at Object.emitEvent (c:\workspace\newrepo3\azure-sdk-for-js\packages\@azure\servicebus\data-plane\node_modules\rhea-promise\lib\util\utils.ts:195:5)
    at Sender._link.on (c:\workspace\newrepo3\azure-sdk-for-js\packages\@azure\servicebus\data-plane\node_modules\rhea-promise\lib\link.ts:292:11)
    at Sender.emit (events.js:182:13)
    at Sender.EventEmitter.emit (domain.js:441:20)
    at Sender.link.dispatch (c:\workspace\newrepo3\azure-sdk-for-js\packages\@azure\servicebus\data-plane\node_modules\rhea\lib\link.js:59:37)
2019-02-16T23:57:28.675Z rhea:events [connection-1] Link got event: settled

Verified that wrapping it as string instead works - message gets sent, received and no data/precision is lost.
However, the messageId obtained on receive/peek of same message will be of type string and not number.

cc @ramya-rao-a @bterlson

@ramya-rao-a
Copy link
Contributor Author

ramya-rao-a commented Feb 17, 2019

On updating this to wrap it as double/float value

Where was this update done?

@ramya0820
Copy link
Member

On updating this to wrap it as double/float value

Where was this update done?

In same place as the link I have referenced in comment.
If messageId was found to be of type 'number', then we directly attempt to parse it as ulong using types.wrap_ulong() utility. So intercepted this in wrap_message_id() function by adding isDecimal checks to the transpiled JS file as follows:

types.wrap_message_id = function(o) {
    var t = typeof o;
    if (t === 'string') {
        return types.wrap_string(o);
    } else if (t === 'number' || o instanceof Number) {
        var isDecimal = (o - Math.floor(o)) !== 0; 
        if(isDecimal) return types.wrap_double(o); 
        // Or wrap into string as: return types.wrap_string(o.toString());
        return types.wrap_ulong(o);
    } else if (Buffer.isBuffer(o)) {
        return types.wrap_uuid(o);
    } else {
        //TODO handle uuids
        throw new errors.TypeError('invalid message id:' + o);
    }
};

@ramya-rao-a
Copy link
Contributor Author

As per the spec at http://www.amqp.org/sites/amqp.org/files/amqp.pdf, if the message id is a number, it shouldnt have decimal parts.

Therefore, let's just update the sdk to throw an error when user provides such message id

@ramya-rao-a
Copy link
Contributor Author

Closed with #1301

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue requires a change to an existing behavior in the product in order to be resolved. Client This issue points to a problem in the data-plane of the library. Service Bus
Projects
None yet
Development

No branches or pull requests

2 participants