-
Notifications
You must be signed in to change notification settings - Fork 33
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
expose tcp_read/ssl_read errors #713
base: master
Are you sure you want to change the base?
Changes from 5 commits
a4e79e4
ee4ec55
cc9dbe4
92c6d3f
c19b7fb
ea110d5
64741be
1de86ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -261,9 +261,14 @@ static int l_tm_tcp_read (lua_State* L) | |
uint8_t buf[512]; | ||
size_t buf_len = sizeof(buf); | ||
int err = tm_tcp_read(socket, buf, &buf_len); | ||
(void) err; | ||
|
||
if (err != 0) { | ||
lua_pushstring(L, "tcp read error"); | ||
lua_error(L); | ||
} else { | ||
colony_pushbuffer(L, buf, buf_len); | ||
} | ||
|
||
colony_pushbuffer(L, buf, buf_len); | ||
return 1; | ||
} | ||
|
||
|
@@ -427,9 +432,13 @@ static int l_tm_ssl_read (lua_State* L) | |
uint8_t buf[20000]; | ||
size_t buf_len = sizeof(buf); | ||
int err = tm_ssl_read(session, buf, &buf_len); | ||
(void) err; | ||
if (err != 0) { | ||
lua_pushstring(L, "ssl read error"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
lua_error(L); | ||
} else { | ||
colony_pushbuffer(L, buf, buf_len); | ||
} | ||
|
||
colony_pushbuffer(L, buf, buf_len); | ||
return 1; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,9 +195,11 @@ TCPSocket.prototype.connect = function (/*options | [port], [host], [cb]*/) { | |
var closeRet = tm.tcp_close(self.socket); // returns -57 if socket is already closed | ||
if (closeRet < 0 && closeRet != -tm.ENOTCONN){ | ||
// couldn't close socket, throw an error | ||
// failed to connect, stay silent | ||
console.log("Failed to close socket", self.socket); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the opposite of staying silent There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But yeah, should we have internal code be emitting console.logs if it's just going to throw the error immediately? |
||
self.emit('error', new Error('ENOENT Cannot close socket ' + self.socket + ' Got: err'+closeRet)); | ||
self.destroy(); | ||
return self.__close(false); | ||
return self.__close(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be |
||
} | ||
|
||
if (retries > 3) { | ||
|
@@ -425,9 +427,17 @@ TCPSocket.prototype.__readSocket = function(restartTimeout) { | |
var arr = [], flag = 0; | ||
while (self.socket != null && (flag = tm.tcp_readable(self.socket)) > 0) { | ||
if (self._ssl) { | ||
var data = tm.ssl_read(self._ssl); | ||
try { | ||
var data = tm.ssl_read(self._ssl); | ||
} catch(e){ | ||
self.emit("error", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} else { | ||
var data = tm.tcp_read(self.socket); | ||
try { | ||
var data = tm.tcp_read(self.socket); | ||
} catch(e){ | ||
self.emit("error", e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
} | ||
} | ||
if (!data || data.length == 0) { | ||
break; | ||
|
@@ -463,11 +473,11 @@ TCPSocket.prototype.__close = function (tryToClose) { | |
function closeSocket(){ | ||
if (self.socket === null) return; | ||
var ret = tm.tcp_close(self.socket); | ||
|
||
if (ret < 0 && ret != -tm.ENOTCONN) { // -57 is inactive, socket has already been closed | ||
if (retries > 3) { | ||
// tried 3 times and couldn't close, error out | ||
self.emit('error', new Error('ENOENT Cannot close socket ' + self.socket + ' Got: err'+ret)); | ||
// removing this error for now, nothing for the user to do if this error occurs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this socket error occurs, what is going to happen downstream? Remove the commented out line underneath this and explain more what the reprecussion of not handling this error looks like. |
||
// self.emit('error', new Error('ENOENT Cannot close socket ' + self.socket + ' Got: err'+ret)); | ||
self.emit('close'); | ||
} else { | ||
retries++; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See ssl read for a better error formatting strategy