I'm encountering a RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds error while working with Google Cloud Pub/Sub in a Node.js application. Below is a simplified version of the service I'm using:
@Controller() export class EventController { private subscription; @Get('subscribe') public subscribe(): void { console.log('Subscribing to event'); this.stringSubscriber.subscribe(); console.log('Subscribed to event'); } private stringSubscriber = { subscribe: (): void => { try { this.subscription.on('message', async (message: Message): Promise<void> => { logger.info('[subscribe] [onMessage] message', { message: message.data.toString(), deliveryAttempt: message.deliveryAttempt, }); await this.handleEvent({ message }); }); } catch (error) { logger.error('[subscribe] Error while subscribing', { error }); throw error; } } }; private async handleEvent(event: { message: Message }): Promise<void> { .... } } it seems to fail when I send a subscribe request to the pod, however it does print the logs before:
Subscribing to event.
Subscribed to event.
node:events:498 throw er; // Unhandled 'error' event ^ RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: "length" is outside of buffer bounds at proto.utf8Write (node:internal/buffer:1066:13) at Op.writeStringBuffer [as fn] (file:///usr/app/apps/demo5/dist/dummy.js:38758:13) at BufferWriter.finish (file:///usr/app/apps/demo5/dist/dummy.js:38708:14) at file:///usr/app/apps/demo5/dist/dummy.js:45199:113 at Array.map (<anonymous>) at createPackageDefinition (file:///usr/app/apps/demo5/dist/dummy.js:45199:41) at Object.fromJSON (file:///usr/app/apps/demo5/dist/dummy.js:45226:14) at _GrpcClient.loadProtoJSON (file:///usr/app/apps/demo5/dist/dummy.js:68212:51) at new IamClient (file:///usr/app/apps/demo5/dist/dummy.js:84620:37) at new SubscriberClient (file:///usr/app/apps/demo5/dist/dummy.js:88646:26) * Ensured that the subscription is properly created and initialized. * Verified that the message handling logic is correct and does not introduce any buffer issues.
dist/dummy.js) which makes the stacktrace less helpful. Can you help identify what data the code is attempting to use with_GrpcClient.loadProtoJSON(dummy.jsline 68212) and/orObject.fromJSON(dummy.jsline 42226)? It certainly seems as though this is an error in the Google library. Please includepackage.jsontoo.4.6.0) version of `@google-cloud/pubsub