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

Installing OPA - extension server exited #682

Closed
scoop96 opened this issue Apr 25, 2024 · 20 comments
Closed

Installing OPA - extension server exited #682

scoop96 opened this issue Apr 25, 2024 · 20 comments
Labels
bug Something isn't working

Comments

@scoop96
Copy link

scoop96 commented Apr 25, 2024

Hi, we are starting to test OPA-Rego at work, and i found in the repo a similar closed issue with regal two weeks ago.
OS is a windows 10.

When I add the opa VSCODE extension it installs regal and opa, i added them to the path (both account and system environmental variables)

here is the VSCODE Output from regal

panic: runtime error: index out of range [0] with length 0

goroutine 19 [running]:
github.com/styrainc/regal/pkg/config.FindRegalDirectory({0xc0002b47c1, 0x1d})
	/home/runner/work/regal/regal/pkg/config/config.go:138 +0x465
github.com/styrainc/regal/pkg/config.FindConfig({0xc0002b47c1?, 0xc0002d81e0?})
	/home/runner/work/regal/regal/pkg/config/config.go:147 +0x1c
github.com/styrainc/regal/internal/lsp.(*LanguageServer).handleInitialize(0xc000096880, {0x140?, 0x15b2220?}, 0xc0002b21e0?, 0xc0002b0ba0)
	/home/runner/work/regal/regal/internal/lsp/server.go:1024 +0x517
github.com/styrainc/regal/internal/lsp.(*LanguageServer).Handle(0xc000096880, {0x1b7f1e8, 0xc0000afc20}, 0xc00008ca20, 0xc0002b0ba0)
	/home/runner/work/regal/regal/internal/lsp/server.go:102 +0x191
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc00008aeb0, {0x1b7f1e8, 0xc0000afc20}, 0xc00008ca20, 0xc0002b0ba0)
	/home/runner/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/handler_with_error.go:21 +0x57
github.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc00008ca20, {0x1b7f1e8, 0xc0000afc20})
	/home/runner/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:205 +0x2dd
created by github.com/sourcegraph/jsonrpc2.NewConn in goroutine 1
	/home/runner/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:62 +0x1e6
[Error - 10:05:40 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 10:05:40 AM] Connection to server got closed. Server will not be restarted.
[Error - 10:05:40 AM] Regal LSP client client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 10:05:40 AM] Server process exited with code 2.

Here is the VSCODE settings.json from the extensions

    "opa.dependency_paths.opa": "C:\\Users\\SE99236\\opa.exe",
    "opa.dependency_paths.regal": "C:\\Users\\SE99236\\regal.exe",
    "opa.languageServers": [
        "regal"
    ]
@anderseknert
Copy link
Member

Hi there @scoop96! And thanks for filing an issue, although I obviously wish you didn't have to 🙂

The trace you provided (thanks for that too!) suggests the issue is encountered when Regal traverses your directory tree looking for a config file:

// Move up one level in the directory tree
parts := strings.Split(dir, rio.PathSeparator)
parts = parts[:len(parts)-1] // <-- referencing index 0 in an empty slice here which causes the panic

I'm not sure why this would happen, but at least it's obvious where it happens. The docs for strings.Split says:

Split slices s into all substrings separated by sep and returns a slice of the substrings between those separators.

If s does not contain sep and sep is not empty, Split returns a slice of length 1 whose only element is s.

If sep is empty, Split splits after each UTF-8 sequence. If both s and sep are empty, Split returns an empty slice.

The second argument here comes from os.PathSeparator and that should never be empty. It's not documented above, but it seems like strings.Split("", "\\") also returns an empty slice, which is likely what's happening here. I'll try and fix that.

In the meantime, do you have a Regal config file in your project workspace? I suppose that if Regal finds one, it won't keep searching, which could be a workaround in the meantime. Just create a .regal/config.yaml file in your project root directory, and put something in there: https://github.com/styraInc/regal?tab=readme-ov-file#configuration

Let me know if that helps work around the issue for the time being.

@anderseknert anderseknert added the bug Something isn't working label Apr 25, 2024
@anderseknert
Copy link
Member

Btw, @scoop96, what does the path to your workspace look like? Just curious if there's anything in that (like special characters, whitespace, etc) that could cause issues here.

@scoop96
Copy link
Author

scoop96 commented Apr 25, 2024

First i started without config file, after so i added a config file (default one as indicated here in de official doc)

Im adding it again by default, allow me to clean something and I'll show you the workspace directory

@anderseknert
Copy link
Member

Did adding a config file help stop the server from crashing?

Just to clarify, I don't need to know what your workspace looks like, only what the path to the workspace looks like. I.e. something like C:\Foo\Bar\Baz

@scoop96
Copy link
Author

scoop96 commented Apr 25, 2024

Here is my workspace
image

Here is the URL path
image

And as indicated in the origin, opa and regal are inside of /Users/SE99236/

@scoop96
Copy link
Author

scoop96 commented Apr 25, 2024

Did adding a config file help stop the server from crashing?

Just to clarify, I don't need to know what your workspace looks like, only what the path to the workspace looks like. I.e. something like C:\Foo\Bar\Baz

Nope, its still the same output

image

@scoop96
Copy link
Author

scoop96 commented Apr 25, 2024

In my OS, we need to ask for a superior team to give us admin permissions.

Does the OPA extension need them? in order to do that configuration manually myself.

Cybersecurity things :)

@anderseknert
Copy link
Member

No, no admin permissions needed 🙂 Thank you for all the details provided! I'm still not sure what would cause this, and I don't have a windows machine at hand, but I'll try my best to see if I can reproduce this in some way. I'll keep you posted!

anderseknert added a commit that referenced this issue Apr 25, 2024
As reported in #682, the server panics when the dir for whatever reason
is "". I don't yet know how to trigger this, and the result of this fix
is likely that the config file won't be found when this happens. But as
a temporary measure I prefer to have Regal run with default configuration
compared to crashing.

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue Apr 25, 2024
As reported in #682, the server panics when the dir for whatever reason
is "". I don't yet know how to trigger this, and the result of this fix
is likely that the config file won't be found when this happens. But as
a temporary measure I prefer to have Regal run with default configuration
compared to crashing.

Signed-off-by: Anders Eknert <anders@styra.com>
@scoop96
Copy link
Author

scoop96 commented Apr 25, 2024

After the commit, i updated the .exe and the issue still on, same thing.

@anderseknert
Copy link
Member

Did you build Regal yourself? If not, you'll have to get the v0.21.2 release from here: https://github.com/StyraInc/regal/releases/tag/v0.21.2

@scoop96
Copy link
Author

scoop96 commented Apr 25, 2024

The first download was wrong, after using the v0.21.2 the error still on, that is odd am i right?

In the new error the comment Server process exited with code 2. its in a different possition

panic: runtime error: index out of range [0] with length 0

goroutine 35 [running]:
github.com/styrainc/regal/pkg/config.FindRegalDirectory({0xc0004025a1, 0x1d})
	/home/runner/work/regal/regal/pkg/config/config.go:144 +0x497
github.com/styrainc/regal/pkg/config.FindConfig({0xc0004025a1?, 0xc0004281e0?})
	/home/runner/work/regal/regal/pkg/config/config.go:153 +0x1c
github.com/styrainc/regal/internal/lsp.(*LanguageServer).handleInitialize(0xc00011ce00, {0x140?, 0x9a2220?}, 0xc00018e3b0?, 0xc00041e000)
	/home/runner/work/regal/regal/internal/lsp/server.go:1024 +0x517
github.com/styrainc/regal/internal/lsp.(*LanguageServer).Handle(0xc00011ce00, {0xf6f388, 0xc00037ce60}, 0xc0000db320, 0xc00041e000)
	/home/runner/work/regal/regal/internal/lsp/server.go:102 +0x191
github.com/sourcegraph/jsonrpc2.(*HandlerWithErrorConfigurer).Handle(0xc00038a1e0, {0xf6f388, 0xc00037ce60}, 0xc0000db320, 0xc00041e000)
	/home/runner/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/handler_with_error.go:21 +0x57
github.com/sourcegraph/jsonrpc2.(*Conn).readMessages(0xc0000db320, {0xf6f388, 0xc00037ce60})
	/home/runner/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:205 +0x2dd
created by github.com/sourcegraph/jsonrpc2.NewConn in goroutine 1
	/home/runner/go/pkg/mod/github.com/sourcegraph/jsonrpc2@v0.2.0/conn.go:62 +0x1e6
[Error - 4:50:08 PM] Server process exited with code 2.
[Error - 4:50:08 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Error - 4:50:08 PM] Connection to server got closed. Server will not be restarted.
[Error - 4:50:08 PM] Regal LSP client client: couldn't create connection to server.
  Message: Pending response rejected since connection got disposed
  Code: -32097 

@anderseknert
Copy link
Member

Hmm yeah. I'll need a Windows machine to test this on. I'll get back to you when I have that!

@srenatus
Copy link
Member

The added check wasn't enough. We'd need to error out if the length is not greater than 1. It's len=1 here, then we drop a segment, it's empty, and accessing the first element panicks...

@anderseknert
Copy link
Member

@srenatus yep, that's what we get for patching without being able to test properly, I suppose 🤦

Do you have time to submit a fix? I'm in meetings for the next 2 hours. I'll get another patch release out later tonight.

@srenatus
Copy link
Member

No way, I'm on the playground 😅

@anderseknert
Copy link
Member

Lol, alright! I'll need a reviewer anyway, so let's push it out tomorrow.

@anderseknert
Copy link
Member

anderseknert commented Apr 26, 2024

@scoop96 can you try v0.21.3? It'll likely won't find your config (but if it does, let me know!) but at least it shouldn't panic.

@scoop96
Copy link
Author

scoop96 commented Apr 29, 2024

@anderseknert This is the new error output:

2024/04/29 08:46:00 jsonrpc2 handler: notification "$/setTrace" handling error: jsonrpc2: code -32601 message: method not supported: $/setTrace

@anderseknert
Copy link
Member

That’s fine. We don’t support that method yet, so we log that when we receive a request for that. It shouldn’t have any impact on server operations though. Are things working? But config file ignored?

@scoop96
Copy link
Author

scoop96 commented Apr 29, 2024

I was setting it up but seems like the problems tab started working finally. (very new with OPA-Rego)

Thank you so much I do guess (if in a few days i dont drop by this bug is for real solved)

Thank you :)

@scoop96 scoop96 closed this as completed Apr 29, 2024
charlieegan3 added a commit that referenced this issue May 8, 2024
This was causing an issue in the loading of config files on windows #682

Signed-off-by: Charlie Egan <charlie@styra.com>
charlieegan3 added a commit that referenced this issue May 8, 2024
This was causing an issue in the loading of config files on windows #682

Signed-off-by: Charlie Egan <charlie@styra.com>
anderseknert pushed a commit that referenced this issue May 8, 2024
This was causing an issue in the loading of config files on windows #682

Signed-off-by: Charlie Egan <charlie@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants