Open emathis11 opened 4 years ago
You need to run your API calls in withContext(dispatcher) { }
block, where dispatcher
is a dispatcher scheduling via ThreadManager
.
You need to run your API calls in
withContext(dispatcher) { }
block, wheredispatcher
is a dispatcher scheduling viaThreadManager
.
The problem is that it seems like that the thread needs to be created on the thread of the request.
So far I have only managed to achieve this by subclassing ServletApplicationEngine
and in serve
initialise a CoroutineDispatcher
from a ThreadPoolService
with one core thread using ThreadManager.currentRequestThreadFactory()
.
Then making sure that the thread is created before super.serve
is called by invoking prestartAllCoreThreads
on the executor.
This is extremely hacky and will definitely cause issues if the same servlet instance is used to serve multiple requests
Thanks for the hint. I'll think how to integrate it properly.
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.
Hey, I've posted a question on youtrack and also quoting it here as I'm not sure what is currently being used to track issues
Hey, is there any news related to this issue? I'm currently trying to call App engine APIs and still receiving this error
java.lang.NullPointerException: Current thread is not associated with any request and is not a background thread
I'm using latest Ktor version, 2.3.2 and it is kinda strange that this was not addressed yet, am I missing something, using it wrongly maybe?
This is the sdk I'm using: implementation("com.google.appengine:appengine-java-sdk:2.0.16") and I'm trying to send an email from Ktor using app engine's Java.mail implementation.
I have followed the instructions to run a Ktor server on App Engine standard environment but unfortunately, this only works as long as you're not calling any App Engine APIs. When you call any of them, it fails with the following error:
The Google Cloud java library APIs don't have this threading limitation, but unfortunately I can't use them as I need to access the App Engine Memcache service, which is only available through the App Engine APIs.
Is there any way around it?