Skip to content
This repository has been archived by the owner on Sep 7, 2022. It is now read-only.

http request to localhost is hanging #42

Open
maxdevp opened this issue Jan 12, 2020 · 10 comments
Open

http request to localhost is hanging #42

maxdevp opened this issue Jan 12, 2020 · 10 comments

Comments

@maxdevp
Copy link

maxdevp commented Jan 12, 2020

Trying to send websocket messages to connected clients by making a call to http://localhost:3001/@connections/{connectionId} however all http calls to localhost:3000 or localhost:3001 are hanging. Works if the lambda function is invoked directly, without serverless-offline-scheduler.

@pardini-net7
Copy link

I'm facing the same problem with s3 offline (but also with a bucket on a real s3).
It hangs on the upload of a file after the cron is triggered.
I think that this plugin doesn't work with http requests... could you help?

@maxdevp
Copy link
Author

maxdevp commented Jan 14, 2020

Noticed it only happens if scheduler is started with "sls offline". Requests work fine if started with sls schedule

@ajmath
Copy link
Owner

ajmath commented Jan 14, 2020 via email

@maxdevp
Copy link
Author

maxdevp commented Jan 14, 2020

Not familiar with the code base.. wondering if it could be related to the order of scheduler and serverless start, http calls to outside domains work, it only hangs if we're calling lambda function (by making a request to localhost) within the scheduler that was started with sls offline start

@ajmath
Copy link
Owner

ajmath commented Jan 14, 2020 via email

@ten-alk
Copy link

ten-alk commented Feb 7, 2020

@maxgedikli There is a workaround that helped me with a similar issue - sending HTTP requests to localhost in scheduled Lambda functions:

diff --git a/node_modules/serverless-offline-scheduler/lib/scheduler.js b/node_modules/serverless-offline-scheduler/lib/scheduler.js
index a03283e..96d2695 100644
--- a/node_modules/serverless-offline-scheduler/lib/scheduler.js
+++ b/node_modules/serverless-offline-scheduler/lib/scheduler.js
@@ -85,7 +85,7 @@ class Scheduler {
         args.push(`--${key}`, `${slsOption[key]}`);
       }
     }
-    return childProcess.execFileSync(process.argv[0], args, { cwd: "./", stdio: "inherit" });
+    return childProcess.spawn(process.argv[0], args, { cwd: "./", stdio: "inherit" });
   }
 
   _setEnvironmentVars(functionName) {

Not sure if if's the right approach or not - I don't have a capacity atm to debug further, but it works for my use cases.

@rokso
Copy link

rokso commented Feb 10, 2020

I am having same issue and here is my observation.
I have 2 lambda functions, one is just cron (no HTTP) and other accepts HTTP requests.

  • Invoke sls offline start
  • cron is scheduled(every minute) and HTTP request to other function works
  • HTTP request hangs after first trigger of cron function (after 1 minute)
  • no scope of using sls schedule in my case

PS: Cron is being triggered only once. It may or may not be an issue based on design of this plugin.

@jkruse14
Copy link

jkruse14 commented Mar 6, 2020

The issue is with execFileSync, here's the documentation:

The child_process.execFileSync() method is generally identical to child_process.execFile() with the exception that the method will not return until the child process has fully closed. When a timeout has been encountered and killSignal is sent, the method won't return until the process has completely exited.

Note: ** the method will not return until the child process has fully closed.**

If you do not close network connections, i.e. redis, mysql, the process will never return. If you set the lambda context callbackWaitsForEmptyEventLoop property to false, your lambda will return right when the handler/controller returns on AWS and not be concerned with those pesky connections (which will be reused). However, that is not taken into account with the plugin.

I have a potential fix and will open a PR.

@jkruse14
Copy link

jkruse14 commented Mar 6, 2020

see #46

@olegario96
Copy link

@rokso same issue here, but instead HTTP I'm using Kinesis events.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants