Skip to content

Commit d8b8711

Browse files
author
Ryan Phillips
committed
fix(net): double callback
1 parent 64d4295 commit d8b8711

File tree

8 files changed

+18
-19
lines changed

8 files changed

+18
-19
lines changed

.luacheckrc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ globals = {
33
"p", "exports", "process", "args", "_ENV"
44
}
55
unused_args = false
6-
ignore = { "122" }
7-
6+
ignore = { "122", "421", "422", "423", "431", "432", "433" }

deps/http.lua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ function ServerResponse:flushHeaders()
107107
self:writeHead(self.statusCode, self.headers)
108108
end
109109

110-
function ServerResponse:write(chunk)
110+
function ServerResponse:write(chunk, callback)
111111
self:flushHeaders()
112-
return self.socket:write(self.encode(chunk))
112+
return self.socket:write(self.encode(chunk), callback)
113113
end
114114

115115
function ServerResponse:finish(chunk)
@@ -120,11 +120,12 @@ function ServerResponse:finish(chunk)
120120
end
121121
last = last .. (self.encode("") or "")
122122
if #last > 0 then
123-
self.socket:write(last)
124-
end
125-
self.socket:shutdown(function()
123+
self.socket:write(last, function()
124+
self.socket:_end()
125+
end)
126+
else
126127
self.socket:_end()
127-
end)
128+
end
128129
end
129130

130131
function ServerResponse:writeHead(statusCode, headers)

deps/net.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,11 @@ function Socket:_write(data, callback)
9494
uv.write(self._handle, data, function(err)
9595
timer.active(self)
9696
if err then
97-
callback(err)
9897
self:destroy(err)
99-
return
98+
return callback(err)
10099
end
100+
callback()
101101
end)
102-
callback()
103102
end
104103

105104
function Socket:_read(n)

deps/url.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ local querystring = require('querystring')
2323
function exports.parse(url, parseQueryString)
2424
local href = url
2525
local chunk, protocol = url:match("^(([a-z0-9+]+)://)")
26+
local auth
2627
url = url:sub((chunk and #chunk or 0) + 1)
27-
28-
local chunk, auth = url:match('(([0-9a-zA-Z]+:?[0-9a-zA-Z]+)@)')
28+
chunk, auth = url:match('(([0-9a-zA-Z]+:?[0-9a-zA-Z]+)@)')
2929
url = url:sub((chunk and #chunk or 0) + 1)
3030

3131
local host = url:match("^([^/]+)")

make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@ECHO off
2-
@SET LIT_VERSION=1.0.3
2+
@SET LIT_VERSION=1.1.2
33

44
IF NOT "x%1" == "x" GOTO :%1
55

tests/test-fs-readstream.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]]
3030

3131

3232
test('fs.readstream length', function(expect)
33-
local tmp_file = path.join(module.dir, 'test_readstream')
33+
local tmp_file = path.join(module.dir, 'test_readstream1.txt')
3434
fs.writeFileSync(tmp_file, text)
3535

3636
local options = {
@@ -60,7 +60,7 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]]
6060
end)
6161

6262
test('fs.readstream offset and length', function(expect)
63-
local tmp_file = path.join(module.dir, 'test_readstream')
63+
local tmp_file = path.join(module.dir, 'test_readstream2.txt')
6464
fs.writeFileSync(tmp_file, text)
6565

6666
local options = {
@@ -90,7 +90,7 @@ proident, sunt in culpa qui officia deserunt mollit anim id est laborum.]]
9090
end)
9191

9292
test('fs.readstream offset only', function(expect)
93-
local tmp_file = path.join(module.dir, 'test_readstream')
93+
local tmp_file = path.join(module.dir, 'test_readstream3.txt')
9494
fs.writeFileSync(tmp_file, text)
9595

9696
local options = {

tests/test-http-post-1mb.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ require('tap')(function(test)
4444
assert(postBuffer == data)
4545
response:write(data)
4646
response:finish()
47-
server:close()
4847
end))
4948
end)
5049

@@ -69,6 +68,7 @@ require('tap')(function(test)
6968
end))
7069
response:on('end', expect(function(data)
7170
p('Response ended')
71+
server:close()
7272
end))
7373
end)
7474
req:write(data)

tests/test-http-stream-finish.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ require('tap')(function(test)
77
local body = "Hello world\n"
88
res:on("finish", expect(function()
99
p('sending resp finished')
10-
server:close()
1110
end))
1211
res:writeHead(200, {
1312
["Content-Type"] = "text/plain",
@@ -18,6 +17,7 @@ require('tap')(function(test)
1817
http.get('http://127.0.0.1:8080', expect(function(resp)
1918
resp:on('end', expect(function(data)
2019
p('Get response ended')
20+
server:close()
2121
end))
2222
end))
2323
end)

0 commit comments

Comments
 (0)