Sonic-pi: Critical Error. One or more ports is not available.

Created on 29 May 2020  路  12Comments  路  Source: sonic-pi-net/sonic-pi

Both Portable & msi windows 10

Critical Error. One or more ports is not available.

[GUI] - Welcome to the Sonic Pi GUI
[GUI] - ===========================
[GUI] -
[GUI] - {05cab854-9d71-43ac-9884-6d2eb35ca27f}
[GUI] - Discovering port numbers...
[GUI] - Detecting port numbers...
[GUI] - GUI listen to server port 0
[GUI] - port: 0 [Not Available]
[GUI] - Server listen to gui port 0
[GUI] - port: 0 [Not Available]
[GUI] - Server incoming OSC cues port 0
[GUI] - port: 0 [Not Available]
[GUI] - Scsynth port 0
[GUI] - port: 0 [Not Available]
[GUI] - Server send to GUI port 0
[GUI] - port: 0 [Not Available]
[GUI] - GUI send to server port 0
[GUI] - port: 0 [Not Available]
[GUI] - Scsynth send port 0
[GUI] - port: 0 [Not Available]
[GUI] - Erlang router port 0
[GUI] - port: 0 [Not Available]
[GUI] - OSC MIDI out port 0
[GUI] - port: 0 [Not Available]
[GUI] - OSC MIDI in port 0
[GUI] - port: 0 [Not Available]
[GUI] - Websocket port 0
[GUI] - port: 0 [Not Available]
[GUI] - Critical Error. One or more ports is not available.

Sonic Pi Boot Error Report

System Information

  • Sonic Pi version: 3.2.2
  • OS: Windows 10 Version 1909

GUI Log

C:\Users\..\.sonic-pi\log\gui.log

[GUI] - Welcome to the Sonic Pi GUI
[GUI] - ===========================
[GUI] -                            
[GUI] - {ac9f6abb-116d-4b41-ad6c-20a086967348}
[GUI] - Discovering port numbers...
[GUI] - Detecting port numbers...
[GUI] - GUI listen to server port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Server listen to gui port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Server incoming OSC cues port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Scsynth port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Server send to GUI port 0
[GUI] -    port: 0 [Not Available]
[GUI] - GUI send to server port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Scsynth send port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Erlang router port 0
[GUI] -    port: 0 [Not Available]
[GUI] - OSC MIDI out port 0
[GUI] -    port: 0 [Not Available]
[GUI] - OSC MIDI in port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Websocket port 0
[GUI] -    port: 0 [Not Available]
[GUI] - Critical Error. One or more ports is not available.

Server Errors

C:\Users\..\.sonic-pi\log\server-errors.log


Server Output

C:\Users\...\.sonic-pi\log\server-output.log


Scsynth Output

C:\Users\..\.sonic-pi\log\scsynth.log


Process Log

C:\Users\..\.sonic-pi\log\processes.log


Windows boot

Most helpful comment

BTW, I've patched this locally, so the next beta will ship with this fix. If there are no issues during the beta period, i'll ship the next version of Sonic Pi with this patched.

So sorry you've had issues with encoding - it's important to me that Sonic Pi runs in as many locales as possible to lower the barriers to entry. Thanks so much for finding a fix and I really hope you have fun playing with it.

Please do consider joining our friendly community: https://in-thread.sonic-pi.net

All 12 comments

I've the same problem

The problem seems to be with ruby not supporting some encodings (in my case CP720). Change it from here to English:

image

It needs a restart afterward and I am not going to change it since I have programs that are dependent on this setting.

Another way would be to use Windows API to change the encoding of the process but QProcess doesn't seem to support it. Maybe having a .bat file next to the ruby.exe file that changes the encoding of the console via chcp 1252 and then runs the ruby.exe file passing the arguments works but I am not sure.

A workaround for this is to change the ruby's registry.rb code (located at C:\Program Files\Sonic Pi\app\server\native\ruby\lib\ruby\2.7.0\win32) and replace the Encoding.find(Encoding.locale_charmap) with Encoding::UTF_8.

For version 2.7.0 of ruby, you should change the 72nd line.

This works temporarily until the next version is out and this file gets replaced again.

@falahati - wow, thanks so much for looking into this.

Are you aware of any negative side effects for any user by skipping the local charmap discovery and nuking it with UTF 8?

I wonder if there's a way to do this that doesn't require hacking registry.rb.

Out of interest, does this error appear for you when you simply try and start irb from the terminal in your default locale? Or, for example, if you run the following: ruby -e 'puts :hi'

Out of interest, does this error appear for you when you simply try and start irb from the terminal in your default locale? Or, for example, if you run the following: ruby -e 'puts :hi'

Yes, unfortunately, the problem is not with the script but rather happens when Ruby is starting up.

C:\Program Files\Sonic Pi\app\server\native\ruby\bin>ruby -e 'puts :hi'
Traceback (most recent call last):
        13: from <internal:gem_prelude>:1:in `<internal:gem_prelude>'
        12: from <internal:gem_prelude>:1:in `require'
        11: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/2.7.0/rubygems.rb:1397:in `<top (required)>'
        10: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/2.7.0/rubygems.rb:1397:in `require'
         9: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/2.7.0/rubygems/defaults/operating_system.rb:3:in `<top (required)>'
         8: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/site_ruby/2.7.0/ruby_installer/runtime/singleton.rb:27:in `enable_dll_search_paths'
         7: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/site_ruby/2.7.0/ruby_installer/runtime/msys2_installation.rb:99:in `enable_dll_search_paths'
         6: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/site_ruby/2.7.0/ruby_installer/runtime/msys2_installation.rb:89:in `mingw_bin_path'
         5: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/site_ruby/2.7.0/ruby_installer/runtime/msys2_installation.rb:76:in `msys_path'
         4: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/site_ruby/2.7.0/ruby_installer/runtime/msys2_installation.rb:46:in `iterate_msys_paths'
         3: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/site_ruby/2.7.0/ruby_installer/runtime/msys2_installation.rb:46:in `require'
         2: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/2.7.0/win32/registry.rb:4:in `<top (required)>'
         1: from C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/2.7.0/win32/registry.rb:72:in `<module:Win32>'
C:/Program Files/Sonic Pi/app/server/native/ruby/lib/ruby/2.7.0/win32/registry.rb:72:in `find': unknown encoding name - CP720 (ArgumentError)

I believe a .bat file can fix this problem as I described above. However, I didn't test it since I had to recompile the GUI. Something as simple as this might be enough:

ruby.bat:

@chcp 1252 >nul 2>&1
ruby.exe %*

With mainwindow.cpp#L345 changed to:

ruby_path = QDir::toNativeSeparators(root_path + "/app/server/native/ruby/bin/ruby.bat");

Excellent, thanks for this.

Now can you try:

ruby -e 'puts :hi' -E utf-8

Already tried the -E argument. No change, unfortunately. Produces the exact same exception. I didn't test it with QProcess, but using SetConsoleCP() and SetConsoleOutputCP() Windows APIs it is possible to change the terminal encoding of CURRENT process's terminal and therefore its subprocesses.

#include <cstdio>
#include <array>
#include <cstdio>
#include <iostream>
#include <windows.h>

int main()
{
    SetConsoleCP(1252);
    SetConsoleOutputCP(1252);

    auto pipe = _popen(
        R"("C:\Program Files\Sonic Pi\app\server\native\ruby\bin\ruby.exe" -e 'puts :hi')",
        "r"
    );

    if (!pipe) {
        return -1;
    }

    std::array<char, 128> buffer{};
    while (!feof(pipe)) {
        if (fgets(buffer.data(), 128, pipe) != nullptr) {
            std::cout << buffer.data();
        }
    }

    return _pclose(pipe);
}

Since nothing unicode is going through the ruby scripts anyway and since UTF-8 is backward compatible with CP-1252, I don't see a scenario in which forcing the UTF-8 encoding results in anything unexpected. However, I am also in agreement that modifying registry.rb is a hacky way to get around this.


Edit: Suggested ruby.bat changed and tested. Should work. At least works via CMD.

hmm, there must be a way of doing this that doesn't require such low-level manipulation and/or modifying registry.rb. Ruby is typically pretty good with non-ascii encodings given it was designed and implemented in Japan.

However, when googling around I see the registry.rb hack mentioned quite a lot, so perhaps that is currently the best way of fixing this right now.

Given that we ship with our own version of Ruby, and provided it doesn't have any other negative side-effects, then this is something I'm happy to do for future versions.

Do you think this only affects Windows, or perhaps it also affects macOS?

BTW, I've patched this locally, so the next beta will ship with this fix. If there are no issues during the beta period, i'll ship the next version of Sonic Pi with this patched.

So sorry you've had issues with encoding - it's important to me that Sonic Pi runs in as many locales as possible to lower the barriers to entry. Thanks so much for finding a fix and I really hope you have fun playing with it.

Please do consider joining our friendly community: https://in-thread.sonic-pi.net

I don't think this affects macOS, It works in my case but then again I never changed any regional setting on my Mac.

To be specific, this seems to be mainly a problem with Windows since CP720 is an old DOS-era code page for Arabic and is superseded with Windows CP1256. Why Windows decided to use CP720 for Persian and not Arabic in Windows 10, 26 years after the last release of DOS is a mystery to me. I can't really expect ruby to support an old codepage from almost three decades ago.

In any case, I still believe having a Windows only .bat file or .cmd file should solve the problem without any need to modify registry.rb. You can even use the C++ sample to create a tiny invoker for ruby on Windows to do the dirty work for you. In any case, I am just grateful for taking this specific and minor issue seriously.

I have two concerns about making a batch script - firstly is ensuring that we get the correct pid for the process returned back (which would likely require a bit of extra piping work) and secondly setting the codepage to cp1256 for everyone might not be desirable?

Unfortunately my knowledge in the area of codepages is pretty limited currently. However, I guess this concern is also similar to forcing the locale to UTF-8 in registry.rb. Perhaps that might negatively affect some specific encodings where UTF-8 isn't backwards compatible? Still, as you're rightly saying, we're assuming that everything is UTF-8 anyway, so hopefully there shouldn't be a problem.

Closing for now - the next release will include a patched Ruby.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MoiRouhs picture MoiRouhs  路  3Comments

farukbigez picture farukbigez  路  7Comments

AlexandreRangel picture AlexandreRangel  路  7Comments

sbeaumont picture sbeaumont  路  3Comments

ostephagus picture ostephagus  路  4Comments