Skip to content

System.DivideByZeroException within pwsh on linux #618

Description

Environment data

# pwsh -c '
& {
    "PS version: $($PSVersionTable.PSVersion)"
    "PSReadline version: $((Get-Module PSReadline).Version)"
    if ($IsLinux -or $IsOSX) {
        "os: $(uname -a)"
    } else {
        "os: $((dir $env:SystemRoot\System32\cmd.exe).VersionInfo.FileVersion)"
    }
    "PS file version: $((dir $pshome\powershell.exe).VersionInfo.FileVersion)"
}'
PS version: 6.0.0-rc.2
PSReadline version: 
os: Linux 18227f8f3aba 4.4.108-boot2docker #1 SMP Wed Dec 27 23:32:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
dir : Cannot find path '/opt/microsoft/powershell/6.0.0-rc.2/powershell.exe' because it does not exist.
At line:10 char:26
+     "PS file version: $((dir $pshome\powershell.exe).VersionInfo.File ...
+                          ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (/opt/microsoft/.../powershell.exe:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

Steps to reproduce or exception report

  • docker run -it microsoft/vsts-agent
  • in separate shell
    • docker exec -it <id of the container just started> /bin/bash
    • pwsh
PowerShell v6.0.0-rc.2
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS /vsts> 
Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 0 Keys:


Exception:
System.DivideByZeroException: Attempted to divide by zero.
   at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------

Activity

  1. lzybkr commented on Jan 16, 2018

    @lzybkr
    Contributor

    I didn't see any obvious places where this division could take place. If it's easy for you to debug and find the exact line, that would expedite a fix.

  2. lestephane commented on Jan 18, 2018

    @lestephane
    Author

    My hands are a bit full at the moment, and this is not blocking me, but i see older closed issues with the same exception type in PSReadline. I'm not a dotnet guy, so i'm not sure how to debug this... Any pointers welcome.

  3. camalot commented on Jan 26, 2018

    @camalot

    Also running into this with Debian 9

    PowerShell v6.0.1
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    https://aka.ms/pscore6-docs
    Type 'help' to get help.
    
    PS /home/jenkins>
    Oops, something went wrong.  Please report this bug with the details below.
    Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
    -----------------------------------------------------------------------
    Last 0 Keys:
    
    
    Exception:
    System.DivideByZeroException: Attempted to divide by zero.
       at Microsoft.PowerShell.PSConsoleReadLine.Initialize(Runspace runspace, EngineIntrinsics engineIntrinsics)
       at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
    -----------------------------------------------------------------------
    
    PS version: 6.0.1
    PSReadline version: 1.2
    os: Linux 12d4c04b1f0f 4.10.0-42-generic #46~16.04.1-Ubuntu SMP Mon Dec 4 15:57:59 UTC 2017 x86_64 GNU/Linux
    

    Debian 9 Stretch
    Also, there isn't powershell.exe in linux version, it is called pwsh

    I am not sure if it is the situation, but in Completion.cs, there is Rows = (matches.Count + columns - 1) / columns which could result in 0 if columns = 1. And then later on is ColumnWidth * (selectedItem / Rows), which would result in a division by 0.

    I did not see anything specific in PSConsoleReadLine.

    I will add, this does seem promising, because completion of arguments is not working.


    More information.

    It only happens if I launch directly in to pwsh. if I launch /bin/bash then pwsh, i do not get the error.

  4. joachimaumann commented on Mar 16, 2018

    @joachimaumann

    Have the same issue with the vsts container as described by Le Stephane (@lestephane) .
    Container I use getting the issue: https://github.com/microsoft/vsts-agent-docker/blob/3a81525044b23e87b75d3f6b4c7e4feb2d0dca3e/ubuntu/16.04/tfs/2017-u1/standard/Dockerfile

    Its blocking us because we could not use azure powershell sdk https://docs.microsoft.com/de-de/powershell/azure/install-azurermps-maclinux?view=azurermps-5.5.0

    could you please look into this

  5. daxian-dbw commented on Mar 16, 2018

    @daxian-dbw
    Member

    I tried on a Debian 9 container, and couldn't reproduce the crash. Never tried on VSTS container though.

    root@1ed6879ac3d8:/# cat /etc/os-release 
    PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
    NAME="Debian GNU/Linux"
    VERSION_ID="9"
    VERSION="9 (stretch)"
    ID=debian
    HOME_URL="https://www.debian.org/"
    SUPPORT_URL="https://www.debian.org/support"
    BUG_REPORT_URL="https://bugs.debian.org/"
    root@1ed6879ac3d8:/# 
    root@1ed6879ac3d8:/# pwsh
    PowerShell v6.0.2
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    https://aka.ms/pscore6-docs
    Type 'help' to get help.
    
    PS /> gmo
    
    ModuleType Version    Name                                ExportedCommands                         
    ---------- -------    ----                                ----------------                         
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable,...
    Script     2.0.0      PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadL...
    

    One thing to point out, the crash posted by Ryan Conrad (@camalot) at #618 (comment) is with PSReadline 1.2.

  6. joachimaumann commented on Mar 19, 2018

    @joachimaumann

    Dongbo Wang (@daxian-dbw) I added the container link which I can reproduce the issue

  7. daxian-dbw commented on Mar 31, 2018

    @daxian-dbw
    Member

    joachimaumann I cannot reproduce the crash with the docker image microsoft/vsts-agent.
    Could this be related to the host OS? Can you please provide detailed repro steps?
    Please see the screenshot below:

    image

  8. lestephane commented on Apr 1, 2018

    @lestephane
    Author

    I'm not longer able to reproduce with the latest image

    REPOSITORY                             TAG                 IMAGE ID            CREATED             SIZE
    microsoft/vsts-agent                   latest              3b66c4a0d020        5 days ago          5.72GB
    
  9. lzybkr commented on Apr 1, 2018

    @lzybkr
    Contributor

    So OK to close?

  10. lestephane commented on Apr 2, 2018

    @lestephane
    Author
  11. lzybkr commented on Apr 3, 2018

    @lzybkr
    Contributor

    OK, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions