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

Progress emitter throws error if jobId has comma in it #2003

Closed
abdatta opened this issue Mar 24, 2021 · 10 comments
Closed

Progress emitter throws error if jobId has comma in it #2003

abdatta opened this issue Mar 24, 2021 · 10 comments

Comments

@abdatta
Copy link

abdatta commented Mar 24, 2021

I'm getting an error when I set a jobId that has a comma in it.

SyntaxError: Unexpected token h in JSON at position 2
    at JSON.parse (<anonymous>)
    at Redis.messageHandler (/usr/lib/node_modules/@abdatta/bulls-eye/node_modules/bull/lib/queue.js:404:50)
    at Redis.emit (events.js:315:20)
    at DataHandler.handleSubscriberReply (/usr/lib/node_modules/@abdatta/bulls-eye/node_modules/ioredis/built/DataHandler.js:80:32)
    at DataHandler.returnReply (/usr/lib/node_modules/@abdatta/bulls-eye/node_modules/ioredis/built/DataHandler.js:47:18)
    at JavascriptRedisParser.returnReply (/usr/lib/node_modules/@abdatta/bulls-eye/node_modules/ioredis/built/DataHandler.js:21:22)
    at JavascriptRedisParser.execute (/usr/lib/node_modules/@abdatta/bulls-eye/node_modules/redis-parser/lib/parser.js:544:14)
    at Socket.<anonymous> (/usr/lib/node_modules/@abdatta/bulls-eye/node_modules/ioredis/built/DataHandler.js:25:20)
    at Socket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)

On following the error message, I end up on this line

this.emit('global:progress', jobId, JSON.parse(progress));

I see the code tried to extract the jobId using the location of the first comma, but since the jobId itself has a comma in it, it fails the extract the full jobId, and the remaining text is not parseable by JSON.parse.

I need to fix this urgently since a code in production is breaking. I would be grateful if somebody can guide be on how to best fix this.

@manast
Copy link
Member

manast commented Mar 24, 2021

I was not aware of this limitation myself, but after examining the code it seems like it is going to be impossible to fix other than renaming the ids so that they do not include commas...

@manast
Copy link
Member

manast commented Mar 24, 2021

I will see if there is any possibility improving the lua code that actually pubs the progress event.

@abdatta
Copy link
Author

abdatta commented Mar 24, 2021

@manast As a quickfix, can we replace indexOf with lastIndexOf at this line

const commaPos = message.indexOf(',');

I found this line here,

.updateProgress(keys, [progressJson, job.id + ',' + progressJson])
and it seems we only pass job.id + ',' + progress, so since progress can never contain commas, I think it can be guaranteed that the last comma will always be the one separating the progress.

Can you pls confirm if my understanding is correct? I'll raise a PR for the same then.

@manast
Copy link
Member

manast commented Mar 24, 2021

so since progress can never contain commas, I think it can be guaranteed that the last comma will always be the one separating the progress.

but progress can be a json object so it can indeed include commas...

@abdatta
Copy link
Author

abdatta commented Mar 24, 2021

Which is the scenario when progress can be a json object? Can you please help me find it?

@manast
Copy link
Member

manast commented Mar 24, 2021

you can send a complete object as progress

@abdatta
Copy link
Author

abdatta commented Mar 24, 2021

Oh okay, I didn't know that.

Then can we escape commas by passing the entire thing as a stringified json?

.updateProgress(keys, [progressJson, job.id + ',' + progressJson])

For example,

.updateProgress(keys, [progressJson, JSON.stringify({jobId: job.id,  progress})]) 

@manast
Copy link
Member

manast commented Mar 24, 2021

Let me take a deeper look at this later today and i will give you an answer

@abdatta
Copy link
Author

abdatta commented Mar 24, 2021

Thank you for looking into this 😀

@manast
Copy link
Member

manast commented Mar 24, 2021

Take a look at the PR, I wrote it so that we are still backwards compatible with the old way of sending the data: #2004

@manast manast closed this as completed in 00a15ea Mar 24, 2021
abdatta added a commit to abdatta/bulls-eye that referenced this issue Mar 29, 2021
Includes fix for commas-in-id bug: OptimalBits/bull#2003
papandreou added a commit to papandreou/bull that referenced this issue Apr 27, 2021
* develop: (39 commits)
  chore(release): 3.22.3 [skip ci]
  fix(delayed): re-schedule updateDelay in case of error fixes OptimalBits#2015
  chore(release): 3.22.2 [skip ci]
  chore: fix github token
  chore: correct release branch
  test: increase timeout in test
  chore: add semantic release scripts
  fix(obliterate): obliterate many jobs fixes OptimalBits#2016
  3.22.1
  chore: upgrade dependencies
  chore: update CHANGELOG
  fix(obliterate): remove repeatable jobs fixes OptimalBits#2012
  docs: fix typo
  docs: update README.md
  docs: updated README.md
  Update README.md
  3.22.0
  docs: update CHANGELOG
  feat: do not rely on comma to encode jobid in progress fixes OptimalBits#2003 (OptimalBits#2004)
  3.21.1
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants