Closed dandaka closed 1 year ago
Does this only happen on cloudflare workers?
Is it a bug in the documentation?
No. The code is correct.
Do you want me to create a Workers project to reproduce the issue?
We certainly need to be able to reproduce this if we should fix something, yes.
I'm not really sure how this is even possible, because grammY works the exact same way for both code snippets, so the error must somehow depend on content of the JSON payload in the request. This can hardly be the case.
It would be even more helpful if you are able to reproduce this locally somehow, rather than on CFW. If you manage to do this, please share the instructions.
Is it possible to run Telegram webhooks locally? I am keen to try.
Is there no way to run your CF Workers application locally?
Otherwise, you can always use tools like ngrok to tunnel the requests to your machine.
Also, you can change your code to use long polling instead of webhooks.
Yep, there is a way to run Workers locally. I am just curious about how to ask Telegram to send webhooks to a local machine. Will check ngrok.
You can also just use curl or Postman to send artificial updates to your bot. A number of example updates are linked at the top of https://grammy.dev under Resources > Example Updates.
Are you able to reproduce this now?
Working on it, combining a repo that you can deploy and reproduce the issue.
On localhost, the script loads indefinitely and crashes with an "out of memory" error.
That is very strange. Looking forward to seeing the code …
https://github.com/dandaka/grammy-workers-bug
This is the code. When I reply with a simple message, it works well. When I try to use answerCallbackQuery, I see the following errors on Workers (not on local env)
Connected to workers-grammy-bug, waiting for logs...
POST https://workers-grammy-bug.accuraten.workers.dev/ - Exception Thrown @ 2/21/2023, 3:12:24 PM
✘ [ERROR] Error: The script will never generate a response.
When I use ngrok to send requests to a local machine, I get super long loading and error in local machine logs:
<--- Last few GCs --->
[74543:0x148040000] 172940 ms: Scavenge 3606.8 (4122.4) -> 3597.0 (4124.1) MB, 11.8 / 0.0 ms (average mu = 0.127, current mu = 0.071) allocation failure;
[74543:0x148040000] 172978 ms: Scavenge 3610.9 (4124.4) -> 3601.0 (4126.4) MB, 10.5 / 0.0 ms (average mu = 0.127, current mu = 0.071) allocation failure;
[74543:0x148040000] 173019 ms: Scavenge 3615.3 (4126.6) -> 3605.4 (4128.4) MB, 15.5 / 0.0 ms (average mu = 0.127, current mu = 0.071) allocation failure;
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x104748794 node::Abort() [/usr/local/bin/node]
2: 0x104748984 node::ModifyCodeGenerationFromStrings(v8::Local<v8::Context>, v8::Local<v8::Value>, bool) [/usr/local/bin/node]
3: 0x10489b790 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0x104a46704 v8::internal::EmbedderStackStateScope::EmbedderStackStateScope(v8::internal::Heap*, v8::internal::EmbedderStackStateScope::Origin, cppgc::EmbedderStackState) [/usr/local/bin/node]
5: 0x104a4a30c v8::internal::Heap::CollectSharedGarbage(v8::internal::GarbageCollectionReason) [/usr/local/bin/node]
6: 0x104a47300 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::internal::GarbageCollectionReason, char const*, v8::GCCallbackFlags) [/usr/local/bin/node]
7: 0x104a44758 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
8: 0x104a39490 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
9: 0x104a39cc0 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x104a1f3d8 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x104a16fe0 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [/usr/local/bin/node]
12: 0x104ca2da8 v8::internal::Handle<v8::internal::NameDictionary> v8::internal::HashTable<v8::internal::NameDictionary, v8::internal::NameDictionaryShape>::EnsureCapacity<v8::internal::Isolate>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::NameDictionary>, int, v8::internal::AllocationType) [/usr/local/bin/node]
13: 0x104ca37f0 v8::internal::Handle<v8::internal::NameDictionary> v8::internal::Dictionary<v8::internal::NameDictionary, v8::internal::NameDictionaryShape>::Add<v8::internal::Isolate>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::NameDictionary>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyDetails, v8::internal::InternalIndex*) [/usr/local/bin/node]
14: 0x104ca3764 v8::internal::BaseNameDictionary<v8::internal::NameDictionary, v8::internal::NameDictionaryShape>::Add(v8::internal::Isolate*, v8::internal::Handle<v8::internal::NameDictionary>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyDetails, v8::internal::InternalIndex*) [/usr/local/bin/node]
15: 0x104c52294 v8::internal::JSObject::SetNormalizedProperty(v8::internal::Handle<v8::internal::JSObject>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyDetails) [/usr/local/bin/node]
16: 0x104c812f8 v8::internal::LookupIterator::TransitionToAccessorPair(v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes) [/usr/local/bin/node]
17: 0x104c80b58 v8::internal::LookupIterator::TransitionToAccessorProperty(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes) [/usr/local/bin/node]
18: 0x104c4ce94 v8::internal::JSObject::DefineAccessor(v8::internal::LookupIterator*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyAttributes) [/usr/local/bin/node]
19: 0x104c4cb8c v8::internal::JSReceiver::ValidateAndApplyPropertyDescriptor(v8::internal::Isolate*, v8::internal::LookupIterator*, bool, v8::internal::PropertyDescriptor*, v8::internal::PropertyDescriptor*, v8::Maybe<v8::internal::ShouldThrow>, v8::internal::Handle<v8::internal::Name>) [/usr/local/bin/node]
20: 0x104c4bc28 v8::internal::JSReceiver::OrdinaryDefineOwnProperty(v8::internal::LookupIterator*, v8::internal::PropertyDescriptor*, v8::Maybe<v8::internal::ShouldThrow>) [/usr/local/bin/node]
21: 0x104c4bac4 v8::internal::JSReceiver::OrdinaryDefineOwnProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSObject>, v8::internal::PropertyKey const&, v8::internal::PropertyDescriptor*, v8::Maybe<v8::internal::ShouldThrow>) [/usr/local/bin/node]
22: 0x104c4b6d4 v8::internal::JSReceiver::DefineOwnProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Object>, v8::internal::PropertyDescriptor*, v8::Maybe<v8::internal::ShouldThrow>) [/usr/local/bin/node]
23: 0x104c4b540 v8::internal::JSReceiver::DefineProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/bin/node]
24: 0x10492aad4 v8::internal::Builtin_ObjectDefineProperty(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
25: 0x1050f918c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/usr/local/bin/node]
26: 0x109c6c150
27: 0x105081700 construct_stub_create_deopt_addr [/usr/local/bin/node]
28: 0x109c50fd0
29: 0x109c368fc
30: 0x109c3a9e4
31: 0x1050b5e14 Builtins_AsyncFunctionAwaitRejectClosure [/usr/local/bin/node]
32: 0x105144898 Builtins_PromiseRejectReactionJob [/usr/local/bin/node]
33: 0x1050a7d64 Builtins_RunMicrotasks [/usr/local/bin/node]
34: 0x1050823a4 Builtins_JSRunMicrotasksEntry [/usr/local/bin/node]
35: 0x1049c7eb0 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
36: 0x1049c83a0 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
37: 0x1049c857c v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*, v8::internal::MaybeHandle<v8::internal::Object>*) [/usr/local/bin/node]
38: 0x1049eecc8 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [/usr/local/bin/node]
39: 0x1049ef560 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [/usr/local/bin/node]
40: 0x10490c0a0 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/usr/local/bin/node]
41: 0x10490bb9c v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
42: 0x10490b3c8 v8::internal::Builtin_HandleApiCall(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
43: 0x1050f918c Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/usr/local/bin/node]
44: 0x109b78a68
45: 0x1050824d0 Builtins_JSEntryTrampoline [/usr/local/bin/node]
46: 0x105082164 Builtins_JSEntry [/usr/local/bin/node]
47: 0x1049c7ee0 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [/usr/local/bin/node]
48: 0x1049c7414 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>*) [/usr/local/bin/node]
49: 0x1048b77b8 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/usr/local/bin/node]
50: 0x104698d18 node::InternalCallbackScope::Close() [/usr/local/bin/node]
51: 0x104698fe8 node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/usr/local/bin/node]
52: 0x1046adb1c node::AsyncWrap::MakeCallback(v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [/usr/local/bin/node]
53: 0x104766534 node::(anonymous namespace)::Parser::OnStreamRead(long, uv_buf_t const&) [/usr/local/bin/node]
54: 0x104801fe0 node::LibuvStreamWrap::OnUvRead(long, uv_buf_t const*) [/usr/local/bin/node]
55: 0x10480277c node::LibuvStreamWrap::ReadStart()::$_1::__invoke(uv_stream_s*, long, uv_buf_t const*) [/usr/local/bin/node]
56: 0x10506f254 uv__stream_io [/usr/local/bin/node]
57: 0x10507736c uv__io_poll [/usr/local/bin/node]
58: 0x105065098 uv_run [/usr/local/bin/node]
59: 0x104699704 node::SpinEventLoop(node::Environment*) [/usr/local/bin/node]
60: 0x104784d14 node::NodeMainInstance::Run() [/usr/local/bin/node]
61: 0x104716614 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [/usr/local/bin/node]
62: 0x104716898 node::Start(int, char**) [/usr/local/bin/node]
63: 0x193e0be50 start [/usr/lib/dyld]
Try pre-setting the bot info.
new Bot(token, { botInfo: /* result of `getMe` */ })
[mf:err] Unhandled Promise Rejection: SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Request.json (/Users/dandaka/projects/workers-grammy-bug/node_modules/undici/lib/fetch/body.js:404:19)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at Request.json (/Users/dandaka/projects/workers-grammy-bug/node_modules/@miniflare/core/src/standards/http.ts:338:18)
It seems like cloudflare shipped a new version. Can you simply try again?
What exactly was updated? I have updated wrangler to the latest wrangler 2.11.0. Same problems, script not working.
Can you share the exact curl command that you use to test your bot?
There is a person who is more familiar with CFW but they do not have a GitHub account. They are a member of https://t.me/grammyjs, however. Asking the same question in the group chat may be a more efficient way to resolve this. Feel free to just share a link to this issue, we'll know.
Continued in https://t.me/grammyjs/114386
Now
Documentation here https://grammy.dev/plugins/keyboard.html#responding-to-clicks
This does not work for me
Cloudflare Workers gives 500 with the error "This request will never generate a response"
Is it a bug in the documentation?
This works for me