Haskell can't bind for second test for Extract URL Path

The test runner seems to succeed and terminate the program

Debug = true
[tester::#IH0] Running tests for Stage #IH0 (Extract URL path)
[tester::#IH0] Running program
[tester::#IH0] $ ./your_program.sh
[your_program] Logs from your program will appear here
[your_program] Listening on 127.0.0.1:4221
[tester::#IH0] Connected to localhost port 4221
[tester::#IH0] $ curl -v http://localhost:4221/blueberry
[tester::#IH0] > GET /blueberry HTTP/1.1
[tester::#IH0] > Host: localhost:4221
[tester::#IH0] > 
[tester::#IH0] Sent bytes: "GET /blueberry HTTP/1.1\r\nHost: localhost:4221\r\n\r\n"
[tester::#IH0] Received bytes: "HTTP/1.1 404 Not Found\r\n\r\n"
[tester::#IH0] < HTTP/1.1 404 Not Found
[tester::#IH0] < 
[tester::#IH0] Received response with 404 status code
[tester::#IH0] Test passed.
[tester::#IH0] Terminating program
[your_program] Accepted connection from 127.0.0.1:44160.
[your_program] Request method "GET".
[your_program] Request target "/blueberry".
[your_program] Sent 26 bytes
[tester::#IH0] Program terminated successfully

But then it can’t bind the port for the next test:

[tester::#IA4] Running tests for Stage #IA4 (Respond with 200)
[tester::#IA4] Running program
[tester::#IA4] $ ./your_program.sh
[your_program] Logs from your program will appear here
[your_program] Listening on 127.0.0.1:4221
[your_program] codecrafters-http-server-exe: Network.Socket.bind: resource busy (Address already in use)
[tester::#IA4] Failed to create connection: dial tcp 127.0.0.1:4221: connect: connection refused
[tester::#IA4] Test failed
[tester::#IA4] Terminating program
[tester::#IA4] Program terminated successfully

It does sometimes seem to take a second after terminating to clean everything up and release the port locally

@Suibeom, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

@andy1li GitHub - Suibeom/HaskellHTTPCodeCrafters Here you go!

@Suibeom You can resolve the issue by using setSocketOption serverSocket ReuseAddr 1 to tell the operating system “Yes, I know the address might be in use, but I want to reuse it anyway.”