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

rails console will not suspend #361

Closed
etcetc opened this issue Nov 5, 2014 · 6 comments
Closed

rails console will not suspend #361

etcetc opened this issue Nov 5, 2014 · 6 comments

Comments

@etcetc
Copy link

etcetc commented Nov 5, 2014

When using spring, I am unable to ctl-Z out of the rails console. While it looks like it's in the shell, if I just hit return it goes back into the rails console. After that, nothing makes sense as it seems to drop letters.

thumbz> rails c
Loading development environment (Rails 4.1.7)
2.1.3 :001 > User
 => User (call 'User.connection' to establish a connection) 
2.1.3 :002 > 
[1]+  Stopped                 rails c
thumbz> 
2.1.3 :003 >   User
-bash: Ue: command not found
thumbz> User
NameError: undefined local variable or method `srUe' for main:Object
from (irb):3
from /Users/ff/.rvm/gems/ruby-2.1.3@rails41/gems/railties-4.1.7/lib/rails/commands/console.rb:90:in `start'
from /Users/ff/.rvm/gems/ruby-2.1.3@rails41/gems/railties-4.1.7/lib/rails/commands/console.rb:9:in `start'
from /Users/ff/.rvm/gems/ruby-2.1.3@rails41/gems/railties-4.1.7/lib/rails/commands/commands_tasks.rb:69:in `console'

At this point, my only recourse is to kill the terminal shell.

This is running on Yosemite on Mac. I have tried w/ ruby 1.9.3 and 2.1, and with rails 4.0 and 4.1.

@casper
Copy link

casper commented Jan 2, 2015

I have exactly the same problem. It seems the spring server is somehow attached to the PTY of the shell. So even if you suspended the spring console command, the server is still reading and writing to the PTY.

Killing the server with kill -HUP frees the shell to start working again. So it's definitely the server that is causing the problem. The client should probably trap SIGTSTP and tell the server to disengage from the PTY before the client process is suspended.

@casper
Copy link

casper commented Jan 2, 2015

This seems to fix the problem:

--- lib/spring/client/run.rb      2015-01-02 11:11:40.737995931 +0200
***************
*** 95,100 ****
--- 95,112 ----
            log "got pid: #{pid}"

            forward_signals(pid.to_i)
+
+           Kernel.trap("TSTP") {
+             log "suspended"
+             Process.kill("STOP", pid.to_i)
+             Process.kill("STOP", Process.pid)
+           }
+
+           Kernel.trap("CONT") {
+             log "resumed"
+             Process.kill("CONT", pid.to_i)
+           }
+

Kache added a commit to Kache/spring that referenced this issue Feb 16, 2017
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal

as mentioned by @casper in Issue rails#361:
> the spring server is somehow attached to the PTY of the shell

the solution is to:
> trap SIGTSTP and tell the server to disengage from the PTY
> before the client process is suspended
Kache added a commit to Kache/spring that referenced this issue Feb 16, 2017
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal

as mentioned by @casper in Issue rails#361:
> the spring server is somehow attached to the PTY of the shell

the solution is to:
> trap SIGTSTP and tell the server to disengage from the PTY
> before the client process is suspended
Kache added a commit to Kache/spring that referenced this issue Feb 16, 2017
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal

as mentioned by @casper in Issue rails#361:
> the spring server is somehow attached to the PTY of the shell

the solution is to:
> trap SIGTSTP and tell the server to disengage from the PTY
> before the client process is suspended
@pavelz
Copy link

pavelz commented Apr 24, 2017

will this be merged soon? spring is useful except when it doesn't suspend.

@pavelz
Copy link

pavelz commented Apr 24, 2017

Still does not work, but commenting out "guard-rails" gem did help.

@casper
Copy link

casper commented Apr 24, 2017

Still does not work, but commenting out "guard-rails" gem did help.

Are you sure you killed all background processes before you tested the patch? You have to manually check everything with ps to make sure. It's easy to leave the Spring server running accidentally, and the client will then reuse it when you think you are restarting everything.

The other option is something has changed since 2015 when I tested it last time, or maybe there is some interaction with guard-rails I'm not aware of.

Kache added a commit to Kache/spring that referenced this issue Sep 12, 2018
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal

as mentioned by @casper in Issue rails#361:
> the spring server is somehow attached to the PTY of the shell

the solution is to:
> trap SIGTSTP and tell the server to disengage from the PTY
> before the client process is suspended
Kache added a commit to Kache/spring that referenced this issue Sep 12, 2018
ctrl-z (SIGTSTP) doesn't work with Spring, and it corrupts the terminal

as mentioned by @casper in Issue rails#361:
> the spring server is somehow attached to the PTY of the shell

the solution is to:
> trap SIGTSTP and tell the server to disengage from the PTY
> before the client process is suspended
jeremy added a commit that referenced this issue Nov 19, 2018
Suspend and Resume on TSTP and CONT signals #361
@jeremy
Copy link
Member

jeremy commented Nov 19, 2018

Closed by #514

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants