Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c9585e

Browse filesBrowse files
committed
Allow up to a second of pings for each runtime to reach the server
1 parent 78995b1 commit 9c9585e
Copy full SHA for 9c9585e

File tree

Expand file treeCollapse file tree

9 files changed

+84
-46
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

9 files changed

+84
-46
lines changed
Open diff view settings
Collapse file

‎dotnetcore2.0/run/MockBootstraps/MockRuntime.cs‎

Copy file name to clipboardExpand all lines: dotnetcore2.0/run/MockBootstraps/MockRuntime.cs
+19-3Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,26 @@ public bool KeepInvokeLoopRunning()
6969

7070
public void Init()
7171
{
72-
var result = client.GetAsync("http://127.0.0.1:9001/2018-06-01/ping").Result;
73-
if (result.StatusCode != HttpStatusCode.OK)
72+
var timeout = DateTimeOffset.Now.AddSeconds(1);
73+
while (true)
7474
{
75-
throw new Exception("Got a bad response from the bootstrap");
75+
try
76+
{
77+
var result = client.GetAsync("http://127.0.0.1:9001/2018-06-01/ping").Result;
78+
if (result.StatusCode != HttpStatusCode.OK)
79+
{
80+
throw new Exception("Got a bad response from the bootstrap");
81+
}
82+
break;
83+
}
84+
catch (Exception e)
85+
{
86+
if (DateTimeOffset.Now > timeout)
87+
{
88+
throw e;
89+
}
90+
}
91+
Thread.Sleep(5);
7692
}
7793
}
7894

Collapse file

‎dotnetcore2.1/run/MockBootstraps/MockRuntime.cs‎

Copy file name to clipboardExpand all lines: dotnetcore2.1/run/MockBootstraps/MockRuntime.cs
+19-3Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,26 @@ public bool KeepInvokeLoopRunning()
6969

7070
public void Init()
7171
{
72-
var result = client.GetAsync("http://127.0.0.1:9001/2018-06-01/ping").Result;
73-
if (result.StatusCode != HttpStatusCode.OK)
72+
var timeout = DateTimeOffset.Now.AddSeconds(1);
73+
while (true)
7474
{
75-
throw new Exception("Got a bad response from the bootstrap");
75+
try
76+
{
77+
var result = client.GetAsync("http://127.0.0.1:9001/2018-06-01/ping").Result;
78+
if (result.StatusCode != HttpStatusCode.OK)
79+
{
80+
throw new Exception("Got a bad response from the bootstrap");
81+
}
82+
break;
83+
}
84+
catch (Exception e)
85+
{
86+
if (DateTimeOffset.Now > timeout)
87+
{
88+
throw e;
89+
}
90+
}
91+
Thread.Sleep(5);
7692
}
7793
}
7894

Collapse file

‎go1.x/run/aws-lambda-mock.go‎

Copy file name to clipboardExpand all lines: go1.x/run/aws-lambda-mock.go
+7-16Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,17 @@ func main() {
108108

109109
defer mockServerCmd.Wait()
110110

111-
maxRetries := 20
111+
pingTimeout := time.Now().Add(1 * time.Second)
112112

113-
for i := 1; i <= maxRetries; i++ {
113+
for {
114114
resp, err := http.Get(apiBase + "/ping")
115115
if err != nil {
116-
if uerr, ok := err.(*url.Error); ok {
117-
if oerr, ok := uerr.Unwrap().(*net.OpError); ok {
118-
// Connection refused, try again
119-
if oerr.Op == "dial" && oerr.Net == "tcp" {
120-
if i == maxRetries {
121-
log.Fatal("Mock server did not start in time")
122-
return
123-
}
124-
time.Sleep(5 * time.Millisecond)
125-
continue
126-
}
127-
}
116+
if time.Now().After(pingTimeout) {
117+
log.Fatal("Mock server did not start in time")
118+
return
128119
}
129-
log.Fatal(err)
130-
return
120+
time.Sleep(5 * time.Millisecond)
121+
continue
131122
}
132123
if resp.StatusCode != 200 {
133124
log.Fatal("Non 200 status code from local server")
Collapse file

‎java8/run/lambda-runtime-mock/src/main/java/lambdainternal/LambdaRuntime.java‎

Copy file name to clipboardExpand all lines: java8/run/lambda-runtime-mock/src/main/java/lambdainternal/LambdaRuntime.java
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public class LambdaRuntime {
9999
}
100100

101101
public static void initRuntime() {
102-
for (int i = 0; i < 20; i++) {
102+
long pingTimeout = System.currentTimeMillis() + 1000;
103+
while (true) {
103104
try {
104105
HttpURLConnection conn = (HttpURLConnection) new URL(API_BASE + "/ping").openConnection();
105106
int responseCode = conn.getResponseCode();
@@ -108,7 +109,7 @@ public static void initRuntime() {
108109
}
109110
break;
110111
} catch (Exception e) {
111-
if (i < 19)
112+
if (System.currentTimeMillis() < pingTimeout)
112113
continue;
113114
throw new RuntimeException(e);
114115
}
Collapse file

‎nodejs4.3/run/awslambda-mock.js‎

Copy file name to clipboardExpand all lines: nodejs4.3/run/awslambda-mock.js
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ OPTIONS.invokeid = OPTIONS.invokeId
8282

8383
var invoked = false
8484
var errored = false
85-
var pingPromise = new Promise(resolve => ping(PING_RETRIES, resolve))
86-
var reportDonePromise = new Promise(resolve => resolve())
85+
var pingPromise
86+
var reportDonePromise
8787

8888
module.exports = {
89-
initRuntime: function () { return OPTIONS },
89+
initRuntime: function () {
90+
pingPromise = new Promise(resolve => ping(Date.now() + 1000, resolve))
91+
reportDonePromise = new Promise(resolve => resolve())
92+
return OPTIONS
93+
},
9094
waitForInvoke: function (cb) {
9195
Promise.all([pingPromise, reportDonePromise]).then(() => {
9296
http.get({
@@ -169,13 +173,13 @@ module.exports = {
169173
maxLoggerErrorSize: 256 * 1024,
170174
}
171175

172-
function ping(retries, cb) {
176+
function ping(timeout, cb) {
173177
http.get({ hostname: '127.0.0.1', port: 9001, path: '/2018-06-01/runtime/ping' }, cb).on('error', () => {
174-
if (!retries) {
178+
if (Date.now() > timeout) {
175179
console.error('Mock server did not respond to pings in time')
176180
process.exit(1)
177181
}
178-
setTimeout(ping, 5, retries - 1, cb)
182+
setTimeout(ping, 5, timeout, cb)
179183
})
180184
}
181185

Collapse file

‎nodejs6.10/run/awslambda-mock.js‎

Copy file name to clipboardExpand all lines: nodejs6.10/run/awslambda-mock.js
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ OPTIONS.invokeid = OPTIONS.invokeId
8282

8383
var invoked = false
8484
var errored = false
85-
var pingPromise = new Promise(resolve => ping(PING_RETRIES, resolve))
86-
var reportDonePromise = new Promise(resolve => resolve())
85+
var pingPromise
86+
var reportDonePromise
8787

8888
module.exports = {
89-
initRuntime: function () { return OPTIONS },
89+
initRuntime: function () {
90+
pingPromise = new Promise(resolve => ping(Date.now() + 1000, resolve))
91+
reportDonePromise = new Promise(resolve => resolve())
92+
return OPTIONS
93+
},
9094
waitForInvoke: function (cb) {
9195
Promise.all([pingPromise, reportDonePromise]).then(() => {
9296
http.get({
@@ -169,13 +173,13 @@ module.exports = {
169173
maxLoggerErrorSize: 256 * 1024,
170174
}
171175

172-
function ping(retries, cb) {
176+
function ping(timeout, cb) {
173177
http.get({ hostname: '127.0.0.1', port: 9001, path: '/2018-06-01/runtime/ping' }, cb).on('error', () => {
174-
if (!retries) {
178+
if (Date.now() > timeout) {
175179
console.error('Mock server did not respond to pings in time')
176180
process.exit(1)
177181
}
178-
setTimeout(ping, 5, retries - 1, cb)
182+
setTimeout(ping, 5, timeout, cb)
179183
})
180184
}
181185

Collapse file

‎nodejs8.10/run/awslambda-mock.js‎

Copy file name to clipboardExpand all lines: nodejs8.10/run/awslambda-mock.js
+10-6Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,15 @@ OPTIONS.invokeid = OPTIONS.invokeId
8282

8383
var invoked = false
8484
var errored = false
85-
var pingPromise = new Promise(resolve => ping(PING_RETRIES, resolve))
86-
var reportDonePromise = new Promise(resolve => resolve())
85+
var pingPromise
86+
var reportDonePromise
8787

8888
module.exports = {
89-
initRuntime: function () { return OPTIONS },
89+
initRuntime: function () {
90+
pingPromise = new Promise(resolve => ping(Date.now() + 1000, resolve))
91+
reportDonePromise = new Promise(resolve => resolve())
92+
return OPTIONS
93+
},
9094
waitForInvoke: function (cb) {
9195
Promise.all([pingPromise, reportDonePromise]).then(() => {
9296
http.get({
@@ -169,13 +173,13 @@ module.exports = {
169173
maxLoggerErrorSize: 256 * 1024,
170174
}
171175

172-
function ping(retries, cb) {
176+
function ping(timeout, cb) {
173177
http.get({ hostname: '127.0.0.1', port: 9001, path: '/2018-06-01/runtime/ping' }, cb).on('error', () => {
174-
if (!retries) {
178+
if (Date.now() > timeout) {
175179
console.error('Mock server did not respond to pings in time')
176180
process.exit(1)
177181
}
178-
setTimeout(ping, 5, retries - 1, cb)
182+
setTimeout(ping, 5, timeout, cb)
179183
})
180184
}
181185

Collapse file

‎python2.7/run/runtime_mock.py‎

Copy file name to clipboardExpand all lines: python2.7/run/runtime_mock.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def report_user_invoke_end():
118118
def receive_start():
119119
global MOCKSERVER_CONN
120120

121-
for retry in range(20):
121+
ping_timeout = time.time() + 1
122+
while True:
122123
try:
123124
MOCKSERVER_CONN = HTTPConnection("127.0.0.1", 9001)
124125
MOCKSERVER_CONN.request("GET", "/2018-06-01/ping")
@@ -128,7 +129,7 @@ def receive_start():
128129
resp.read()
129130
break
130131
except Exception:
131-
if retry >= 19:
132+
if time.time() > ping_timeout:
132133
raise
133134
else:
134135
time.sleep(.005)
Collapse file

‎python3.6/run/runtime_mock.py‎

Copy file name to clipboardExpand all lines: python3.6/run/runtime_mock.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def report_user_invoke_end():
118118
def receive_start():
119119
global MOCKSERVER_CONN
120120

121-
for retry in range(20):
121+
ping_timeout = time.time() + 1
122+
while True:
122123
try:
123124
MOCKSERVER_CONN = HTTPConnection("127.0.0.1", 9001)
124125
MOCKSERVER_CONN.request("GET", "/2018-06-01/ping")
@@ -128,7 +129,7 @@ def receive_start():
128129
resp.read()
129130
break
130131
except Exception:
131-
if retry >= 19:
132+
if time.time() > ping_timeout:
132133
raise
133134
else:
134135
time.sleep(.005)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.