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

Sleeping in javascript/ECMAScript causes HTTP actions to fail #407

Open
edman007 opened this issue Dec 16, 2024 · 0 comments
Open

Sleeping in javascript/ECMAScript causes HTTP actions to fail #407

edman007 opened this issue Dec 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@edman007
Copy link

Expected Behavior

I am attempting to have a rule sleep, and it appears to consistently cause the HTTP actions to fail.

I have two different ways of doing it and the same results.

Method 1

(function (){
  let otp_url = "https://edman007.com/";
  
//returns the OTP, or -1 is one after start does not exist
function getOTP(){
    for (let i = 0; i < 10; i++){
      console.log("Query...")
      let response = actions.HTTP.sendHttpGetRequest(otp_url, 2000);
      if (typeof response != "string"){
        console.log(typeof response)
        console.log(response)
        return "-1"
      }
      java.lang.Thread.sleep(5000);
    }
    return "no problem"
}
    console.log(getOTP());
})();

Method 2

(function (){
  let otp_url = "https://edman007.com/";
  function runQuery(i){
      console.log("Query...")
      let response = ""

        response = actions.HTTP.sendHttpGetRequest(otp_url, 25000);

      if (typeof response != "string"){
        console.log(typeof response)
        console.log(response)
        console.log("problem")
        return
      }
      if (i > 0){
        setTimeout(runQuery, 5000, i-1);
      } else {
        console.log("no problem")
      }
  }
//returns the OTP, or -1 is one after start does not exist
function getOTP(){
    runQuery(10)
    
    
}
  console.log(getOTP());
})();

Current Behavior

Following the sleep (or setTimeout) in the rule, subsequent calls to sendHttpGetRequest fail with one of these errors:

09:33:35.962 [ERROR] [penhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.ExecutionException: java.io.EOFException: @6fde56fc::DecryptedEndPoint@2b539a0d{l=/192.168.1.5:50510,r=edman007.com/54.163.210.121:443,OPEN,fill=-,flush=-,to=5003/0}

Possible Solution

I did get this to show this error once:

2954-2024-12-15 18:47:05.907 [ERROR] [enhab.core.model.script.actions.HTTP] - Fatal transport error: java.util.concurrent.ExecutionException: java.io.EOFException: @28fdcf22::DecryptedEndPoint@52244f71{l=/192.168.1.5:33026,r=edman007.com/54.163.210.121:443,OPEN,fill=-,flush=-,to=5005/0}
2955-2024-12-15 18:47:05.910 [INFO ] [nhab.automation.script.ui.b002b41cfd] - object
2956-2024-12-15 18:47:05.911 [INFO ] [nhab.automation.script.ui.b002b41cfd] - null
2957-2024-12-15 18:47:05.913 [WARN ] [e.automation.internal.RuleEngineImpl] - Failed to execute action: 1(Multi threaded access requested by thread Thread[qtp165409559-27626,5,main] but is not allowed for language(s) js.)
2958:java.lang.IllegalStateException: Multi threaded access requested by thread Thread[qtp165409559-27626,5,main] but is not allowed for language(s) js.
2959-	at com.oracle.truffle.polyglot.PolyglotEngineException.illegalState(PolyglotEngineException.java:129) ~[?:?]
2960-	at com.oracle.truffle.polyglot.PolyglotContextImpl.throwDeniedThreadAccess(PolyglotContextImpl.java:1034) ~[?:?]
2961-	at com.oracle.truffle.polyglot.PolyglotContextImpl.checkAllThreadAccesses(PolyglotContextImpl.java:893) ~[?:?]
2962-	at com.oracle.truffle.polyglot.PolyglotContextImpl.enterThreadChanged(PolyglotContextImpl.java:723) ~[?:?]
2963-	at com.oracle.truffle.polyglot.PolyglotEngineImpl.enterCached(PolyglotEngineImpl.java:1991) ~[?:?]
2964-	at com.oracle.truffle.polyglot.PolyglotEngineImpl.enterIfNeeded(PolyglotEngineImpl.java:1919) ~[?:?]
2965-	at com.oracle.truffle.polyglot.PolyglotValueDispatch.hostEnter(PolyglotValueDispatch.java:1227) ~[?:?]
2966-	at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:1290) ~[?:?]
2967-	at com.oracle.truffle.polyglot.PolyglotContextDispatch.eval(PolyglotContextDispatch.java:63) ~[?:?]
2968-	at org.graalvm.polyglot.Context.eval(Context.java:399) ~[?:?]
2969-	at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.evalInternal(GraalJSScriptEngine.java:376) ~[?:?]
2970-	at com.oracle.truffle.js.scriptengine.GraalJSBindings.deletePropertyFunction(GraalJSBindings.java:101) ~[?:?]
2971-	at com.oracle.truffle.js.scriptengine.GraalJSBindings.remove(GraalJSBindings.java:161) ~[?:?]
2972-	at javax.script.SimpleScriptContext.removeAttribute(SimpleScriptContext.java:214) ~[java.scripting:?]
2973-	at org.openhab.core.automation.module.script.internal.handler.AbstractScriptModuleHandler.resetExecutionContext(AbstractScriptModuleHandler.java:169) ~[?:?]
2974-	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:81) ~[?:?]
2975-	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?]
2976-	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:72) ~[?:?]
2977-	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1188) ~[?:?]
2978-	at org.openhab.core.automation.internal.RuleEngineImpl.runNow(RuleEngineImpl.java:1039) ~[?:?]
2979-	at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:376) ~[?:?]
2980-	at org.openhab.core.automation.rest.internal.RuleResource.runNow(RuleResource.java:393) ~[?:?]
2981-	at jdk.internal.reflect.GeneratedMethodAccessor94.invoke(Unknown Source) ~[?:?]
2982-	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
2983-	at java.lang.reflect.Method.invoke(Method.java:569) ~[?:?]
2984-	at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:179) ~[bundleFile:3.6.2]
2985-	at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) ~[bundleFile:3.6.2]
2986-	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:201) ~[bundleFile:3.6.2]
2987-	at org.apache.cxf.jaxrs.JAXRSInvoker.invoke(JAXRSInvoker.java:104) ~[bundleFile:3.6.2]
2988-	at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) ~[bundleFile:3.6.2]
2989-	at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:96) ~[bundleFile:3.6.2]
2990-	at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307) ~[bundleFile:3.6.2]
2991-	at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) ~[bundleFile:3.6.2]
2992-	at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:265) ~[bundleFile:3.6.2]
2993-	at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) ~[bundleFile:3.6.2]
2994-	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) ~[bundleFile:3.6.2]
2995-	at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) ~[bundleFile:3.6.2]
2996-	at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:225) ~[bundleFile:3.6.2]
2997-	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:304) ~[bundleFile:3.6.2]
2998-	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:217) ~[bundleFile:3.6.2]
2999-	at javax.servlet.http.HttpServlet.service(HttpServlet.java:517) ~[bundleFile:4.0.4]
3000-	at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:279) ~[bundleFile:3.6.2]
3001-	at org.ops4j.pax.web.service.spi.servlet.OsgiInitializedServlet.service(OsgiInitializedServlet.java:102) ~[bundleFile:?]
3002-	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:799) ~[bundleFile:9.4.54.v20240208]
3003-	at org.eclipse.jetty.servlet.ServletHandler$ChainEnd.doFilter(ServletHandler.java:1656) ~[bundleFile:9.4.54.v20240208]
3004-	at org.ops4j.pax.web.service.spi.servlet.OsgiFilterChain.doFilter(OsgiFilterChain.java:113) ~[bundleFile:?]
3005-	at org.ops4j.pax.web.service.jetty.internal.PaxWebServletHandler.doHandle(PaxWebServletHandler.java:334) ~[bundleFile:?]
3006-	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[bundleFile:9.4.54.v20240208]
3007-	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:600) ~[bundleFile:9.4.54.v20240208]
3008-	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.54.v20240208]
3009-	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235) ~[bundleFile:9.4.54.v20240208]
3010-	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1624) ~[bundleFile:9.4.54.v20240208]
3011-	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233) ~[bundleFile:9.4.54.v20240208]
3012-	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1440) ~[bundleFile:9.4.54.v20240208]
3013-	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188) ~[bundleFile:9.4.54.v20240208]
3014-	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:505) ~[bundleFile:9.4.54.v20240208]
3015-	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1594) ~[bundleFile:9.4.54.v20240208]
3016-	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186) ~[bundleFile:9.4.54.v20240208]
3017-	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1355) ~[bundleFile:9.4.54.v20240208]
3018-	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[bundleFile:9.4.54.v20240208]
3019-	at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:234) ~[bundleFile:9.4.54.v20240208]
3020-	at org.ops4j.pax.web.service.jetty.internal.PrioritizedHandlerCollection.handle(PrioritizedHandlerCollection.java:96) ~[bundleFile:?]
3021-	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127) ~[bundleFile:9.4.54.v20240208]
3022-	at org.eclipse.jetty.server.Server.handle(Server.java:516) ~[bundleFile:9.4.54.v20240208]
3023-	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:487) ~[bundleFile:9.4.54.v20240208]
3024-	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:732) [bundleFile:9.4.54.v20240208]
3025-	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:479) [bundleFile:9.4.54.v20240208]
3026-	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:277) [bundleFile:9.4.54.v20240208]
3027-	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311) [bundleFile:9.4.54.v20240208]
3028-	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105) [bundleFile:9.4.54.v20240208]
3029-	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104) [bundleFile:9.4.54.v20240208]
3030-	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:338) [bundleFile:9.4.54.v20240208]
3031-	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:315) [bundleFile:9.4.54.v20240208]
3032-	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:173) [bundleFile:9.4.54.v20240208]
3033-	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131) [bundleFile:9.4.54.v20240208]
3034-	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:409) [bundleFile:9.4.54.v20240208]
3035-	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:883) [bundleFile:9.4.54.v20240208]
3036-	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1034) [bundleFile:9.4.54.v20240208]
3037-	at java.lang.Thread.run(Thread.java:840) [?:?]

That makes me wonder if it's related to/same as jetty/jetty.project#3891 but that was closed years ago.

Steps to Reproduce (for Bugs)

Execute the code posted above, it's 100% reproducible

Context

Cannot poll a webpage in a script without some sort of sleeping

Your Environment

  • Hardware: x86_64/amd
  • OS: debian 11.11
  • Java Runtime Environment: open jdk 17
  • openHAB version: 4.2.3-1
@edman007 edman007 added the bug Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant