Permalink
Browse files

Fix deadlock with concurrent connections to the skip image loading te…

…st app
  • Loading branch information...
1 parent b08726a commit e7ff6d4a18d22da8a3c7ff1fc995bc4c640c5092 @mhoran mhoran committed May 15, 2012
Showing with 22 additions and 20 deletions.
  1. +22 −20 spec/browser_spec.rb
View
@@ -83,18 +83,19 @@
@port = @server.addr[1]
@received_requests = []
- @server_thread = Thread.new(@server) do |serv|
- while conn = serv.accept do
- # read request
- request = []
- until (line = conn.readline.strip).empty?
- request << line
- end
-
- @received_requests << request.join("\n")
-
- # write response
- html = <<-HTML
+ @server_thread = Thread.new do
+ while conn = @server.accept
+ Thread.new(conn) do |conn|
+ # read request
+ request = []
+ until (line = conn.readline.strip).empty?
+ request << line
+ end
+
+ @received_requests << request.join("\n")
+
+ # write response
+ html = <<-HTML
<html>
<head>
<style>
@@ -107,14 +108,15 @@
<img src="/path/to/image"/>
</body>
</html>
- HTML
- conn.write "HTTP/1.1 200 OK\r\n"
- conn.write "Content-Type:text/html\r\n"
- conn.write "Content-Length: %i\r\n" % html.size
- conn.write "\r\n"
- conn.write html
- conn.write("\r\n\r\n")
- conn.close
+ HTML
+ conn.write "HTTP/1.1 200 OK\r\n"
+ conn.write "Content-Type:text/html\r\n"
+ conn.write "Content-Length: %i\r\n" % html.size
+ conn.write "\r\n"
+ conn.write html
+ conn.write("\r\n\r\n")
+ conn.close
+ end
end
end
end

0 comments on commit e7ff6d4

Please sign in to comment.