Skip to content

Conversation

@okjulian
Copy link
Contributor

@okjulian okjulian commented Sep 9, 2018

PostgresPubSub instances emit a special event called "error". This event's payload is an instance of Javascript's Error. You can get the error's text using error.message.

const ps = new PostgresPubSub({ client });
 ps.subscribe("error", err => {
  console.log(err.message); // -> "payload string too long"
}).then(() => ps.publish("a", "a".repeat(9000)));

For example you can log all error messages (including stack traces and friends) using something like this:

ps.subscribe("error", console.error);

@okjulian okjulian added the enhancement New feature or request label Sep 9, 2018
@okjulian okjulian self-assigned this Sep 9, 2018
@derekpitt
Copy link

Looks like it will still send the message, so I'm afraid that it is still going to kill my web server. (although, I will for sure double check)

Maybe the responsibility of the message length check should be on pg-ipc?

I'm also gonna check out some of the other implementations to see if they have to check for limitations.

Thanks for including me in this one! Really don't like the idea of introducing new infra to have cross process communication

@okjulian
Copy link
Contributor Author

You need to listen for the error message. If you do that, your server won't crash. There's an underlying NodeJS Event Emitter that receives an error event when there is a message with over 8000 characters. As you can read in the official docs, any unhandled error event in a NodeJS event emitter will throw an error and terminate the process.

@derekpitt did you try if this is the case? Adding ps.subscribe("error", console.error); to your web server should prevent it from crashing.

@derekpitt
Copy link

Oh man! I never knew that error events were special!

Well then, I love this :)

@okjulian
Copy link
Contributor Author

Awesome! Thanks so much for your help Derek 😄

@okjulian okjulian merged commit c3da5af into master Sep 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants