Powershell: Constant crashing in PowerShell v7 + VSCode Remote Containers + FileSystemWatcher?

Created on 8 Feb 2020  Â·  13Comments  Â·  Source: PowerShell/PowerShell

Environment data

  • MacOS Catalina 10.15.3
  • VSCode 1.42.0
  • VSCode-PowerShell extension 2020.1.0
  • Remote-Containers extension 0.101.0
  • PowerShell v7 RC2

Steps to reproduce

  1. Run a new container docker run --interactive --tty --detach microsoft/powershell:preview
  2. Use VSCode to attach to the container, using the Remote-Containers: Attach to Running Container ... command
  3. Wait for Installing Dev Container ... to finish, in the new VSCode window
  4. Create a PowerShell script file ie. tasks.ps1 (code below)
  5. Go back to the VSCode Explorer view, and create a new file in /root

tasks.ps1

$Watcher = [System.IO.FileSystemWatcher]::new($PSScriptRoot)
$Watcher.WaitForChanged([System.IO.WatcherChangeTypes]::All)

Expected behavior

Container runs without crashing

Actual behavior

PowerShell process / container regularly crashes, at irregular times, with the following log messages.

Docker Logs: Example 1

PowerShell 7.0.0-rc.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS />
PS /> ^[[27;1R^[[27;1R^[[1;7R^[[1;7R^[[1;7R^[[27;1R^[[27;1R^[[27;7R^[[27;7R^[[28;1R^[[28;1R^[[62;7R^[[62;7R^[[27;1R^[[27;1R^[[1;7R^[[1;7R^[[1;7R^[[27;1R^[[27;1R^[[27;7R^[[27;7R^[[28;1R^[[28;1R^[[1;92R^[[1;92R
Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new
### Environment.PowerShell.UnmanagedPSEntry.Start(System.String, System.String[], Int32)
PSReadLine: 2.0.0-rc2Shell.ManagedPSEntry.Main(System.String[])
PowerShell: 7.0.0-rc.2ngeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
OS: Linux 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019
Last 200 KeysConsole.SetCursorPosition(Int32 left, Int32 top)
at System.Console.set_CursorLeft(Int32 value)
 @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ Ctrl+c @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ Ctrl+p p � � � Backspace @ @ Backspace p � � � Backspace @ @ Enter
 @ @ @ @ @ @ @ � � Ctrl+f � � Backspace @ @ @ @ @ @ @ @ @ @ Ctrl+a @ @ @ @ @ @ @ ( � ` � � Backspace @ @ Ctrl+p p � � � Backspace @ @ Backspace p � � � Backspace @ @ x � < � � Backspace @ @ � � ; & � Backspace @ @ Ctrl+p p � � � Backspace @ @ � V c � � Backspace @ @ 0 ' 7 & � Backspace @ @ 0 ' 7 & � Backspace @ @ � o � � � Backspace @ @ � � ; & � Backspace @ @
at Microsoft.PowerShell.ConsoleHost.InputLoop.Run(Boolean inputLoopIsNested)
   at Microsoft.PowerShell.ConsoleHost.InputLoop.RunNewInputLoop(ConsoleHost parent, Boolean isNested)
### Exceptionft.PowerShell.ConsoleHost.EnterNestedPrompt()
at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName)
System.DivideByZeroException: Attempted to divide by zero.meterParser cpp, Boolean isPrestartWarned)
   at Microsoft.PowerShell.PSConsoleReadLine.RenderErrorPrompt(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)ext, String helpText, String[] args)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()rText, String helpText, String[] args)
   at Microsoft.PowerShell.PSConsoleReadLine.CancelLine(Nullable`1 key, Object arg)args, Int32 argc)PowerShell 7.0.0-rc.2
   at Microsoft.PowerShell.PSConsoleReadLine.CopyOrCancelLine(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)
62;136R^C

Docker Logs: Example 2

PowerShell 7.0.0-rc.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

PS />
PS /> erShell_pr����������������t.AutomaSystem.Mshell/7-��V�-�����@���@@�V��ti�V����0pi0pi��V��ti��XLe`�9
Oops, something went wrong.  Please report this bug with the details below.91R^[[1;92R^[[1;93R^[[1;94R^[[1;94R^[[1;94R^[[1;95R^[[1;96R^[[1;97R^[[1;97R^[[1;97R^[[1;98R^[[1;99R^[[1;100R^[[1;100R^[[1;100R^[[1;101R^[[1;102R^[[1;103R^[[1;103R^Report on GitHub: https://github.com/PowerShell/PSReadLine/issues/new
### Environment
PSReadLine: 2.0.0-rc2
PowerShell: 7.0.0-rc.2
OS: Linux 4.19.76-linuxkit #1 SMP Thu Oct 17 19:31:58 UTC 2019
Last 1 Keys
 P

### Exception
System.DivideByZeroException: Attempted to divide by zero.
   at Microsoft.PowerShell.PSConsoleReadLine.PhysicalLineCount(Int32 columns, Boolean isFirstLogicalLine, Int32& lenLastPhysicalLine)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Render()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(PSKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
^[[35;1R^[[35;1R^[[35;7R^[[35;7R   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics, CancellationToken cancellationToken)

                                62;17R^C
Issue-Question

All 13 comments

@pcgeek86 Can you repo without PSReadline?

@iSazonov How are you proposing I do that? Uninstall the PSReadline module after the container starts up? I'm only using the container in its default state, not installing any additional modules. If PSReadline is loaded, then it's not something I'm doing intentionally.

Can you do Remove-Module PSReadline? We need to understand a root of the issue.

@iSazonov I've encountered the same issue, and changed my Dockerfile to do

RUN /usr/bin/pwsh -Command 'Set-Content $PROFILE.AllUsersAllHosts "Remove-Module PSReadLine"'

After that, the original issue is still there, the container crashes when run by VSCode, but the stack trace is different:

PowerShell 7.0.0
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/powershell
Type 'help' to get help.

[?1h=PS /workspace> fProcess terminated. The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was -1.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String, System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. (Parameter 'top')
Actual value was -1.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at System.Console.set_CursorLeft(Int32 value)
   at Microsoft.PowerShell.ConsoleHostUserInterface.ReadLineFromConsole(Boolean endOnTab, String initialContent, Boolean calledFromPipeline, String& restOfLine, ReadLineResult& result) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs:line 1811
   at Microsoft.PowerShell.ConsoleHostUserInterface.ReadLine(Boolean endOnTab, String initialContent, ReadLineResult& result, Boolean calledFromPipeline, Boolean transcribeResult) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs:line 1446
   at Microsoft.PowerShell.ConsoleHostUserInterface.ReadLineWithTabCompletion(Executor exec) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHostUserInterface.cs:line 1919
   at Microsoft.PowerShell.ConsoleHost.InputLoop.Run(Boolean inputLoopIsNested) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 2472
   at Microsoft.PowerShell.ConsoleHost.InputLoop.RunNewInputLoop(ConsoleHost parent, Boolean isNested) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 2322
   at Microsoft.PowerShell.ConsoleHost.EnterNestedPrompt() in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 1019
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 1489
   at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 1456
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, String[] args) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs:line 260
   at Microsoft.PowerShell.ConsoleShell.Start(InitialSessionState initialSessionState, String bannerText, String helpText, String[] args) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs:line 47
   at Microsoft.PowerShell.ConsoleShell.Start(String bannerText, String helpText, String[] args) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs:line 24
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String consoleFilePath, String[] args, Int32 argc) in /PowerShell/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs:line 77

@resnikb Thanks for your confirmation!

@rjmholt @TylerLeonhardt Could you please look the issue with VS Code?

It looks like the problem is with PowerShell (well .NET...) trying to query the Cursor position... It's getting -1 from the terminal.

@tyriar and @daxian-dbw would probably be the experts in this space.

System.DivideByZeroException: Attempted to divide by zero.

This looks extremely similar to https://github.com/PowerShell/PSReadLine/issues/670.
However, the repro is very different from what was reported there.

@pcgeek86 @resnikb Do you see the same crash when just run docker exec to start pwsh (either directly or from bash) after creating the container? I want to see whether the VSCode part is just red herring of the real problem.

@daxian-dbw No, I can run interactive shell without issues, with or without PSReadLine:

  • docker run works
  • docker exec works
  • interactive PowerShell terminal in VS Code works

Here is the minimial docker-compose.yml that reproduces the issue:

version: "3.4"
services:
  repro:
    image: mcr.microsoft.com/powershell:7.0.0-alpine-3.10
    volumes:
      - .:/workspace:cached
    working_dir: /workspace
    tty: true

In VSCode, you can use this file as the container definition, open the folder in container, and after several seconds (up to a minute) the container will crash.

Image mcr.microsoft.com/powershell:6.2.4-alpine-3.8 works fine in the same scenario.

Got the same issue, didn't succeed in running any PS7 Linux image container till now.

Anyone got it to work?

Assign the issue to myself for investigation for now.

@JohnnyVicious I got it to work for VS Code by overriding the command in docker-compose.yml to be:

command: /bin/sh -c "while sleep 1000; do :; done"

@Tyriar that was because the previous implementation of the readline in the PowerShell extension didn't support wrapping of commands to the next line. You'd type a really long command, and it would crash.

That's fixed now as the PowerShell extension relies on PSReadLine. However, that exception was because the value was too large (i.e. 3000 for Console.Top)... but in that case above, Console.Top returns -1 which is odd

Was this page helpful?
5 / 5 - 1 ratings