Skip to content
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

Pass hostname to web socket instead of hardcoded localhost #10571

Closed
wants to merge 3 commits into from
Closed

Pass hostname to web socket instead of hardcoded localhost #10571

wants to merge 3 commits into from

Conversation

mspaulding06
Copy link

@mspaulding06 mspaulding06 commented Apr 2, 2021

When attempting to use the playground with an IP other than "localhost" or "0.0.0.0" the output is unable to update. The following error is thrown when clicking the "Show Output" button in the interface.

Unhandled exception: Error connecting to 'localhost:8080': Connection refused (Socket::ConnectError)
  from /usr/share/crystal/src/socket/addrinfo.cr:73:15 in 'initialize'
  from /usr/share/crystal/src/socket/tcp_socket.cr:27:3 in 'initialize'
  from /usr/share/crystal/src/socket/tcp_socket.cr:27:3 in 'new'
  from /usr/share/crystal/src/http/web_socket/protocol.cr:275:5 in 'new'
  from /usr/share/crystal/src/http/web_socket/protocol.cr:323:14 in 'new'
  from /usr/share/crystal/src/http/web_socket.cr:35:5 in 'new'
  from /usr/share/crystal/src/http/web_socket.cr:34:3 in 'new'
  from /usr/share/crystal/src/compiler/crystal/tools/playground/agent.cr:10:11 in 'initialize'
  from /usr/share/crystal/src/compiler/crystal/tools/playground/agent.cr:9:3 in 'new'
  from /usr/share/crystal/src/gc/boehm.cr:164:23 in '~Crystal::Playground::Agent::instance:init'
  from /play:1:6 in '__crystal_main'
  from /usr/share/crystal/src/crystal/main.cr:110:5 in 'main_user_code'
  from /usr/share/crystal/src/crystal/main.cr:96:7 in 'main'
  from /usr/share/crystal/src/crystal/main.cr:119:3 in 'main'
  from __libc_start_main
  from _start
  from ???

exit status: 1

This is a small change that passes the hostname to the session so that it can be used for the web socket instead of the hardcoded "localhost".

@@ -491,7 +491,7 @@ module Crystal::Playground
ws.close :policy_violation, "Invalid Request Origin"
else
@sessions_key += 1
@sessions[@sessions_key] = session = Session.new(ws, @sessions_key, @port)
@sessions[@sessions_key] = session = Session.new(ws, @sessions_key, @host || "localhost", @port)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default should be set within the initializer.

@mspaulding06
Copy link
Author

Looks like some of the tests have failed because they were unable to communicate with Docker's servers. I don't think I have any way to trigger them to run again.

@HertzDevil
Copy link
Contributor

#12356 is probably a better fix than this PR.

@HertzDevil
Copy link
Contributor

Duplicate of #12356

@HertzDevil HertzDevil marked this as a duplicate of #12356 Aug 14, 2022
@HertzDevil HertzDevil closed this Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants