Theodus / jennet

A simple HTTP web framework written in Pony
BSD 2-Clause "Simplified" License
88 stars 7 forks source link

Example either crash or hangs on Windows #22

Open qonn opened 3 years ago

qonn commented 3 years ago

When I run the main example on Windows, it's either crash (2%) or just hang after several concurrent requests (98%).

Expected Behavior

Pony should never crash or hang once compiled! At least based on jennet implementation, it doesn't really do that much.

Current Behavior

Everything compiled nicely, but once I run the wrk tool via Ubuntu WSL wrk -c100 -d30s --latency http://127.0.0.1:8080/. It will crash or just hang forever instantly within 2 seconds. No errors, nothing. Just a feeling of emptiness.

Current Workaround

I managed to get this working by always adding a Content-Length header to the BuildableResponse, I pretty much use my own BuildableResponse, instead of using the one provided here:

Original: https://github.com/Theodus/jennet/blob/6ed62c9d119879d6fdf571f85feab77bdc28bdd5/jennet/jennet.pony#L172-L186

Mine: image

Steps to Reproduce

  1. Windows Machine?
  2. Ubuntu WSL installed
  3. wrk installed following
  4. Pretty much everything else was just copy pasted from get started with pony mixed with trying to get jennet to run. But i'm going to write the steps anyway starting from step 3 😄
  5. Install Pony https://github.com/ponylang/ponyc/blob/main/INSTALL.md#windows
  6. Install corral https://github.com/ponylang/corral/blob/main/BUILD.md#from-source-windows
  7. Create a new folder? jennet-test
  8. corral init
  9. Install corral dependencies
  10. jennet doesn't use main as the main branch so corral will fail. Thus we have to manually clone the jennet git into _corral folder in the jennet_test/_corral/github_com_theodus_jennet
  11. follow https://github.com/Theodus/jennet#named-parameters example (I do need to change the listening host to 0.0.0.0)
  12. run with command in cmd corral run -- ponyc --define openssl_0.9.0
  13. run wrk with WSL wrk -c100 -d30s --latency http://127.0.0.1:8080/

Context (Environment)

Theodus commented 3 years ago

Hi @qonn! Thanks for bringing up these issues. Apparently the CI has fallen out of sync with Pony releases, which I'm going to fix now. I've just switched the primary branch to "main" instead of "master", and updated the dependencies to support the latest release version of the compiler. You should now be able to run the tests by just cloning the repo and running make test. Let me know if you are still experiencing the same issues on Windows.

qonn commented 3 years ago

Hi @Theodus, no problem! Thanks for the fix, it is easier to get things running now. unfortunately, I did another fresh initialization of jennet, the same example (corral add & corral fetch now works fine). Retest using wrk -c512 -d30s --latency http://127.0.0.1:9999/. 1st run -> crash, 2nd run -> hangs again. 3rd run -> crash and so on...

Also, running make test doesn't really work properly on Windows at least for me. I managed to build the test.exe manually but that's about it, I run the test.exe but no output. just the emptiness of the terminal heheh.

Theodus commented 3 years ago

I don't use Windows, but I suspect a reasonable fix would be to replace Context.respond with the following:

  fun ref respond(res: BuildableResponse iso, res_body: ValBytes = []) =>
    """
    Respond to the given request with the response.
    """
    if res_body.size() > 0 then
      res.add_header("Content-Length", res_body.size().string())
    end
    _responder(consume res, ByteArrays(res_body), this)

Feel free to open a PR if this fix works for you, or if you have an alternative suggestion. Also, if you have had a Pony program crash (like a segfault). it would be good to have some more detail about that because that may be a bug somewhere in the Pony libraries we depend on.