googleapis / nodejs-pubsub

Node.js client for Google Cloud Pub/Sub: Ingest event streams from anywhere, at any scale, for simple, reliable, real-time stream analytics.
https://cloud.google.com/pubsub/
Apache License 2.0
517 stars 227 forks source link

subscription.on('message') causes fatal error "Check failed: AllowJavascriptExecution::IsAllowed(isolate)" #1932

Closed garrettg123 closed 3 months ago

garrettg123 commented 3 months ago

Environment details

Steps to reproduce

Index.ts:

          const pubSubClient = new PubSub({
            keyFile: 'keys/google-pubsub-private-key.json',
          })
          const subscriptionName = `gmail-sub-${user.id}`
          try {
            const subscriptionResult = await pubSubClient.createSubscription(
              PUBSUB_TOPIC,
              subscriptionName
            )
            if (!subscriptionResult) {
              console.error('Error subscribing to Gmail notifications')
              return
            }
            log('Subscribed to Gmail notifications: %O', subscriptionResult)
          } catch (err) {
            if (err instanceof Error && 'code' in err && err.code === 6) {
              log('Subscription already exists - ignoring error')
            } else {
              log('Error subscribing to Gmail notifications', err)
              Sentry.captureException(err)
              throw err
            }
          }

          const subscription = pubSubClient.subscription(subscriptionName)
          subscription.on('message', message => {}) // this line causes error

Error:

# Fatal error in , line 0
# Check failed: AllowJavascriptExecution::IsAllowed(isolate).
#
#
#
#FailureMessage Object: 0x30b5d55f0
----- Native stack trace -----

 1: 0x100d30672 node::NodePlatform::GetStackTracePrinter()::$_3::__invoke() [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 2: 0x10203da13 V8_Fatal(char const*, ...) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 3: 0x100fc2f44 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 4: 0x100fc2135 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 5: 0x100e91056 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 6: 0x100dcadce node::inspector::(anonymous namespace)::JSBindingsConnection<node::inspector::(anonymous namespace)::LocalConnection>::JSBindingsSessionDelegate::SendMessageToFrontend(v8_inspector::StringView const&) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 7: 0x100dc0c75 node::inspector::(anonymous namespace)::ChannelImpl::sendNotification(std::__1::unique_ptr<v8_inspector::StringBuffer, std::__1::default_delete<v8_inspector::StringBuffer>>) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 8: 0x1015789f2 non-virtual thunk to v8_inspector::V8InspectorSessionImpl::SendProtocolNotification(std::__1::unique_ptr<v8_crdtp::Serializable, std::__1::default_delete<v8_crdtp::Serializable>>) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
 9: 0x1017aa020 v8_inspector::protocol::Debugger::Frontend::paused(std::__1::unique_ptr<std::__1::vector<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>, std::__1::allocator<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>>>, std::__1::default_delete<std::__1::vector<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>, std::__1::allocator<std::__1::unique_ptr<v8_inspector::protocol::Debugger::CallFrame, std::__1::default_delete<v8_inspector::protocol::Debugger::CallFrame>>>>>>, v8_inspector::String16 const&, v8_crdtp::detail::PtrMaybe<v8_inspector::protocol::DictionaryValue>, v8_crdtp::detail::PtrMaybe<std::__1::vector<v8_inspector::String16, std::__1::allocator<v8_inspector::String16>>>, v8_crdtp::detail::PtrMaybe<v8_inspector::protocol::Runtime::StackTrace>, v8_crdtp::detail::PtrMaybe<v8_inspector::protocol::Runtime::StackTraceId>, v8_crdtp::detail::PtrMaybe<v8_inspector::protocol::Runtime::StackTraceId>) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
10: 0x1015597dd v8_inspector::V8DebuggerAgentImpl::didPause(int, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::debug::ExceptionType, bool, v8::base::EnumSet<v8::debug::BreakReason, int>) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
11: 0x101553df8 std::__1::__function::__func<v8_inspector::V8Debugger::handleProgramBreak(v8::Local<v8::Context>, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::base::EnumSet<v8::debug::BreakReason, int>, v8::debug::ExceptionType, bool)::$_4, std::__1::allocator<v8_inspector::V8Debugger::handleProgramBreak(v8::Local<v8::Context>, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::base::EnumSet<v8::debug::BreakReason, int>, v8::debug::ExceptionType, bool)::$_4>, void (v8_inspector::V8InspectorSessionImpl*)>::operator()(v8_inspector::V8InspectorSessionImpl*&&) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
12: 0x101573f91 v8_inspector::V8InspectorImpl::forEachSession(int, std::__1::function<void (v8_inspector::V8InspectorSessionImpl*)> const&) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
13: 0x10154e20d v8_inspector::V8Debugger::handleProgramBreak(v8::Local<v8::Context>, v8::Local<v8::Value>, std::__1::vector<int, std::__1::allocator<int>> const&, v8::base::EnumSet<v8::debug::BreakReason, int>, v8::debug::ExceptionType, bool) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
14: 0x10154e5ba v8_inspector::V8Debugger::ExceptionThrown(v8::Local<v8::Context>, v8::Local<v8::Value>, v8::Local<v8::Value>, bool, v8::debug::ExceptionType) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
15: 0x100f7ea42 v8::internal::Debug::OnException(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::debug::ExceptionType) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
16: 0x100f7e5ea v8::internal::Debug::OnThrow(v8::internal::Handle<v8::internal::Object>) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
17: 0x100fd60bd v8::internal::Isolate::ThrowInternal(v8::internal::Object, v8::internal::MessageLocation*) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
18: 0x100fd5ca4 v8::internal::Isolate::StackOverflow() [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
19: 0x1014b0bd6 v8::internal::Runtime_CompileLazy(int, unsigned long*, v8::internal::Isolate*) [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]
20: 0x10188adb6 Builtins_CEntry_Return1_ArgvOnStack_NoBuiltinExit [/Users/gsquare567/.local/share/nvm/v20.14.0/bin/node]

Run: tsx index.ts

When running with --trace-gc option I see: [57114:0x7f98b0008000] 6278 ms: Scavenge 133.5 (156.4) -> 123.1 (157.9) MB, pooled: 0 MB, 1.87 / 0.02 ms (average mu = 0.998, current mu = 0.998) task; or [58517:0x7fb258008000] 4570 ms: Scavenge 124.8 (149.8) -> 111.4 (149.8) MB, 0.95 / 0.02 ms (average mu = 0.995, current mu = 0.996) allocation failure;

garrettg123 commented 3 months ago

The error was caused by logging with the 'debug' package the entire message.