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

mono corrupting console when using Console.Readline() #21758

Open
1 of 4 tasks
harieamjari opened this issue Apr 4, 2024 · 2 comments
Open
1 of 4 tasks

mono corrupting console when using Console.Readline() #21758

harieamjari opened this issue Apr 4, 2024 · 2 comments

Comments

@harieamjari
Copy link

Steps to Reproduce

~ $ cat t.cs
using System;

public class Test {
  static int Main(string[] args) {
    Console.Write("Type some characters: ");
    string s = Console.ReadLine();
    return 0;
  }
}
~ $ mcs t.cs
t.cs(8,12): warning CS0219: The variable `s' is assigned but its value is never used
Compilation succeeded - 1 warning(s)
~ $ mono t.exe
Type some characters: kdkd kdkd
~ $
No command lskw found, did you mean:
 Command ls in package coreutils
 Command lsb in package lrzsz
 Command lsd in package lsd
 Command lsix in package lsix
 Command lsof in package lsof
 Command lsrc in package rcm
 Command lsar in package unar
 Command lsfd in package util-linux
~ $
No command nn found, did you mean:
 Command nm in package binutils
 Command nm in package binutils-is-llvm
 Command ln in package coreutils
 Command gn in package gn
 Command sn in package mono
 Command ne in package ne
 Command nc in package netcat-openbsd
 Command nnn in package nnn
 Command nu in package nushell
 Command nx in package nxengine
 Command nns in package tcllib
 Command sn in package tin-summer
~ $
Erase is delete.
Interrupt is control-C (^C).
~ $ mono t.exe | cat
Type some characters: hi
~ $ echo test
test
~ $

Current Behavior

After a C# program exit with calls to Console.ReadLine(), console now fails to echo characters. (The console's echoing can be restored with reset.)

One temporary remedy is to redirect to stdout to /dev/null or pipe it cat.

Expected Behavior

Console get's restored to it's echoing state

On which platforms did you notice this

  • macOS
  • Linux
  • Windows
  • Android (Termux)

Version Used: 6.12.0.199

Strace

I suspect it's has something to do with termios (which eventually calls ioctl). Redirecting
stdout to somewhere prevents corrupting the console of which the ioctl error as:

~ $ strace mono t.exe 2>&1 | grep ioctl
ioctl(1, TCGETS, 0x7fe9973da0)          = -1 ENOTTY (Not a typewriter)
kdkdkd
~ $

The console get's corrupted with the following ioctl calls (assuming it's the root problem):

~ $ strace mono t.exe 2> dump && grep ioctl dump
Type some characters: blahblah
ioctl(1, TCGETS, {c_iflag=BRKINT|IGNPAR|ICRNL|IXON|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, TCGETS, {c_iflag=BRKINT|IGNPAR|ICRNL|IXON|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, TCGETS, {c_iflag=BRKINT|IGNPAR|ICRNL|IXON|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHO|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, TCSETS, {c_iflag=BRKINT|IGNPAR|ICRNL|IXON|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, TIOCGWINSZ, {ws_row=43, ws_col=96, ws_xpixel=0, ws_ypixel=0}) = 0
ioctl(0, TCGETS, {c_iflag=BRKINT|IGNPAR|ICRNL|IXON|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ICANON|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, TCSETS, {c_iflag=BRKINT|IGNPAR|ICRNL|IMAXBEL|IUTF8, c_oflag=NL0|CR0|TAB0|BS0|VT0|FF0|OPOST|ONLCR, c_cflag=B38400|CS8|CREAD, c_lflag=ISIG|ECHOE|ECHOK|IEXTEN|ECHOCTL|ECHOKE, ...}) = 0
ioctl(0, FIONREAD, [8])                 = 0
ioctl(0, FIONREAD, [8])                 = 0
~ $
@harieamjari
Copy link
Author

Full strace mono t.exe 2> strace.txt
strace.txt

@qrp73
Copy link

qrp73 commented May 26, 2024

I think it may be related with this issue: #21773

Something is definitely going wrong with console.

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

2 participants