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

'Property 'Wait' of object is not a function' when calling .Wait() on a task with the usage of Jint 3.0.1 #1812

Closed
arekpalinski opened this issue Mar 18, 2024 · 5 comments · Fixed by #1830

Comments

@arekpalinski
Copy link

arekpalinski commented Mar 18, 2024

Version used

3.0.1

Describe the bug

We get the following exception in RavenDB with the usage of Jint 3.0.1:

Raven.Client.Exceptions.Documents.Patching.JavaScriptException: At 0:3 Script failed for document ID ''. {"message":"Property 'Wait' of object is not a function","stack":"   at execute (server, database) :3:1\r\n   at :5:1"}
 ---> Jint.Runtime.JavaScriptException: Property 'Wait' of object is not a function
 ---> Error: Property 'Wait' of object is not a function
   at execute (server, database) :3:1
   at :5:1
   --- End of inner exception stack trace ---
   at Jint.Runtime.ExceptionHelper.ThrowJavaScriptException(Engine engine, JsValue value, Completion& result)
   at Jint.Native.Function.ScriptFunction.Call(JsValue thisObject, JsValue[] arguments)
   at Jint.Engine.Call(Function function, JsValue thisObject, JsValue[] arguments, JintExpression expression)
   at Jint.Engine.<>c__DisplayClass133_0.<Call>g__Callback|0()
   at Jint.Engine.ExecuteWithConstraints[T](Boolean strict, Func`1 callback)
   at Jint.Engine.Call(JsValue callable, JsValue thisObject, JsValue[] arguments)
   at Raven.Server.Documents.Patch.ScriptRunner.SingleRun.Run(JsonOperationContext jsonCtx, DocumentsOperationContext docCtx, String method, String documentId, Object[] args, QueryTimingsScope scope, CancellationToken token) in D:\workspace\ravendb-6.0\src\Raven.Server\Documents\Patch\ScriptRunner.cs:line 2114
   --- End of inner exception stack trace ---
   at Raven.Server.Documents.Patch.ScriptRunner.SingleRun.Run(JsonOperationContext jsonCtx, DocumentsOperationContext docCtx, String method, String documentId, Object[] args, QueryTimingsScope scope, CancellationToken token) in D:\workspace\ravendb-6.0\src\Raven.Server\Documents\Patch\ScriptRunner.cs:line 2129
   at Raven.Server.Documents.Patch.ScriptRunner.SingleRun.Run(JsonOperationContext jsonCtx, DocumentsOperationContext docCtx, String method, Object[] args, QueryTimingsScope scope, CancellationToken token) in D:\workspace\ravendb-6.0\src\Raven.Server\Documents\Patch\ScriptRunner.cs:line 2093
   at Raven.Server.Documents.Patch.AdminJsConsole.ApplyScript(AdminJsScript script) in D:\workspace\ravendb-6.0\src\Raven.Server\Documents\Patch\AdminJsConsole.cs:line 44
   at Raven.Server.Web.System.AdminDatabasesHandler.AdminConsole() in D:\workspace\ravendb-6.0\src\Raven.Server\Web\System\AdminDatabasesHandler.cs:line 1017
   at Raven.Server.Routing.RequestRouter.HandlePath(RequestHandlerContext reqCtx) in D:\workspace\ravendb-6.0\src\Raven.Server\Routing\RequestRouter.cs:line 418
   at Raven.Server.RavenServerStartup.RequestHandler(HttpContext context) in D:\workspace\ravendb-6.0\src\Raven.Server\RavenServerStartup.cs:line 192

We have verified it was not happening on 3.0.0

To Reproduce

Run the following code:

server.ServerStore.EnsureNotPassiveAsync(null, "A").Wait();

in RavenDB's Admin JS Console (https://ravendb.net/docs/article-page/6.0/csharp/studio/server/debug/admin-js-console).

EnsureNotPassiveAsync() returns C# Task object.

Expected behavior

No Exception

Additional context

This is happening in RavenDB Server CC @lahma

@arekpalinski
Copy link
Author

Maybe related to #1787?

@ml054
Copy link

ml054 commented Mar 18, 2024

Please also check Result property on task as stated here #1787 (comment)

Thanks :)

@arekpalinski
Copy link
Author

Hi, any update here?

@lahma
Copy link
Collaborator

lahma commented Mar 29, 2024

Well current update is that we are being pinged by a commercial product for free work 🤷🏻‍♂️

Is the calling code owned by you? I think having await for the task would resolve the issue. Not sure if the Task to Promise conversion should be more explicit.

@arekpalinski
Copy link
Author

Marko, don't get me wrong. I decided to ping here since at glance it looked as a regression issue from our perspective so I thought it might be important. There was no response so I thought it could get lost somehow or maybe you already checked it and know something more but didn't update here.

Regarding the actual issue, simply converting the sample script from:

server.ServerStore.EnsureNotPassiveAsync(null, "A").Wait();

to

await server.ServerStore.EnsureNotPassiveAsync(null, "A");

doesn't work for us but this is because the function that we wrap the script provided by a user (like the above) isn't declared as async:

https://github.com/ravendb/ravendb/blob/0ddbe3215a3e6d4814758f9bb4211d3cb9a6f93b/src/Raven.Server/Documents/Patch/AdminJsConsole.cs#L105-L109

runner.AddScript($@"function execute(server, database){{ 

{_script}

}};");

If we change it to:

async function execute(server, database){{ 

{_script}

}};

then the call await server.ServerStore.EnsureNotPassiveAsync(null, "A"); works as expected (our tests checking JS Admin Console feature fail then but this is because now execute function returns JsPromise instead of JsValue so I guess we'll need to use UnwrapIfPromise()).

Do you think that's the way to go for us? We have reverted to Jint 3.0.0 for now but we'd like to do the update it in the next release.

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

Successfully merging a pull request may close this issue.

3 participants