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

bbe1952 panic #5628

Closed
text01001 opened this issue Jul 13, 2023 · 13 comments
Closed

bbe1952 panic #5628

text01001 opened this issue Jul 13, 2023 · 13 comments
Labels
bug 🐞 Something isn't working
Milestone

Comments

@text01001
Copy link

text01001 commented Jul 13, 2023

I use caddy commit: 27bc16a
and
trojan commit: imgk/caddy-trojan@8be6619
(xcaddy --with github.com/imgk/caddy-trojan@master )
full compile command:

CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GOAMD64=v2 xcaddy build 27bc16abedb0b9afc06705ec839c06d908cd91c9 --output /tmp/caddy/caddy --with github.com/mholt/caddy-webdav --with github.com/caddy-dns/cloudflare --with github.com/mholt/caddy-events-exec --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive --with github.com/WeidiDeng/caddy-cloudflare-ip --with github.com/imgk/caddy-trojan@master --with github.com/mholt/caddy-dynamicdns

OS:

uname -a
Linux test 6.0.5 #1 SMP PREEMPT_DYNAMIC Thu Oct 27 06:59:14 CST 2022 x86_64 GNU/Linux

caddy version:

/tmp/caddy/caddy version
v2.7.0-beta.2.0.20230713215448-27bc16abedb0 h1:FZii1qV8q1TfPp6cMK6vPQum5apj29DLptOV5QzbNGI=

Simplified caddy configuration file:

{
	log {
		output file /tmp/caddy/caddy_log.txt
		level INFO
	}
	trojan {
		caddy
		no_proxy
		users pw1234
	}
	servers 127.0.0.1:88 {
		listener_wrappers {
			trojan
		}
	}
}
:88 {
	bind 127.0.0.1
	route {
		reverse_proxy 127.0.0.1:80
	}
}

After caddy starts, it will panic. I don’t know if this is a problem with caddy or a problem with the trojan plugin.

/tmp/caddy/caddy run --config /tmp/caddy/Caddyfile

log:

2023/07/15 02:46:57.148 INFO    using provided configuratio{"config_file": "/tmp/caddy/Caddyfile", "config_adapter": ""}2023/07/15 02:46:57.172 WARN    Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies   {"adapter": "caddyfile", "file": "/tmp/caddy/Caddyfile", "line": 20}
2023/07/15 02:46:57.182 INFO    redirected default logger  {"from": "stderr", "to": "/tmp/caddy/caddy_log.txt"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x10cd562]

goroutine 1 [running]:
github.com/caddyserver/caddy/v2.Context.AppIfConfigured(...)        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/context.go:444
github.com/caddyserver/caddy/v2/modules/caddytls.(*TLS).Cleanup(0xc000671180)
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/modules/caddytls/tls.go:335 +0xa2
github.com/caddyserver/caddy/v2.NewContext.func1()
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/context.go:67 +0x17d
github.com/caddyserver/caddy/v2.run.func1()
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/caddy.go:419 +0x2a
github.com/caddyserver/caddy/v2.run(0xc000464c70?, 0x1)
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/caddy.go:484 +0x81c
github.com/caddyserver/caddy/v2.unsyncedDecodeAndRun({0xc000118780, 0x1c2, 0x1e0}, 0x1)
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/caddy.go:337 +0x145
github.com/caddyserver/caddy/v2.changeConfig({0x1adeb6e, 0x4}, {0x1ae6f91, 0x7}, {0xc0001185a0, 0x1c2, 0x1e0}, {0x0, 0x0}, 0x1)
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/caddy.go:228 +0x79a
github.com/caddyserver/caddy/v2.Load({0xc0001185a0, 0x1c2, 0x1e0}, 0x0?)
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/caddy.go:127 +0x24e
github.com/caddyserver/caddy/v2/cmd.cmdRun({0x0?})
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/cmd/commandfuncs.go:222 +0x945
github.com/caddyserver/caddy/v2/cmd.WrapCommandFuncForCobra.func1(0xc0001dc300?, {0x1adf3b2?, 0x2?, 0x2?})
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/cmd/cobra.go:126 +0x2f
github.com/spf13/cobra.(*Command).execute(0xc0001dc300, {0xc0006551e0, 0x2, 0x2})
        github.com/spf13/cobra@v1.7.0/command.go:940 +0x862
github.com/spf13/cobra.(*Command).ExecuteC(0x2c9a720)
        github.com/spf13/cobra@v1.7.0/command.go:1068 +0x3bdgithub.com/spf13/cobra.(*Command).Execute(...)
        github.com/spf13/cobra@v1.7.0/command.go:992
github.com/caddyserver/caddy/v2/cmd.Main()
        github.com/caddyserver/caddy/v2@v2.7.0-beta.2.0.20230713215448-27bc16abedb0/cmd/main.go:64 +0x5c
main.main()
        caddy/main.go:18 +0x17

After compiling and testing the last few commit versions
Panic started after this commit 0e2c7e1

@mholt
Copy link
Member

mholt commented Jul 13, 2023

Thanks for opening an issue! And ESPECIALLY thank you for trying the latest commits!! You're awesome. I'll look into this.

It's not immediately clear to me what is going on, so I'll need your help to understand it better.

Ideally, we need to be able to reproduce the bug in the most minimal way possible using the latest version of Caddy. This allows us to write regression tests to verify the fix is working. If we can't reproduce it, then you'll have to test our changes for us until it's fixed -- and then we can't add test cases, either.

I've attached a template below that will help make this easier and faster! This will require some effort on your part -- please understand that we will be dedicating time to fix the bug you are reporting if you can just help us understand it and reproduce it easily.

This template will ask for some information you've already provided; that's OK, just fill it out the best you can. 👍 I've also included some helpful tips below the template. Feel free to let me know if you have any questions!

Thank you again for your report, we look forward to resolving it!

Template

## 1. Environment

### 1a. Operating system and version

```
paste here
```


### 1b. Caddy version (run `caddy version` or paste commit SHA)

This should be the latest version of Caddy:

```
paste here
```


## 2. Description

### 2a. What happens (briefly explain what is wrong)




### 2b. Why it's a bug (if it's not obvious)




### 2c. Log output

```
paste terminal output or logs here
```



### 2d. Workaround(s)




### 2e. Relevant links




## 3. Tutorial (minimal steps to reproduce the bug)




Instructions -- please heed otherwise we cannot help you (help us help you!)

  1. Environment: Please fill out your OS and Caddy versions, even if you don't think they are relevant. (They are always relevant.) If you built Caddy from source, provide the commit SHA and specify your exact Go version.

  2. Description: Describe at a high level what the bug is. What happens? Why is it a bug? Not all bugs are obvious, so convince readers that it's actually a bug.

    • 2c) Log output: Paste terminal output and/or complete logs in a code block. DO NOT REDACT INFORMATION except for credentials. Please enable debug and access logs.
    • 2d) Workaround: What are you doing to work around the problem in the meantime? This can help others who encounter the same problem, until we implement a fix.
    • 2e) Relevant links: Please link to any related issues, pull requests, docs, and/or discussion. This can add crucial context to your report.
  3. Tutorial: What are the minimum required specific steps someone needs to take in order to experience the same bug? Your goal here is to make sure that anyone else can have the same experience with the bug as you do. You are writing a tutorial, so make sure to carry it out yourself before posting it. Please:

    • Start with an empty config. Add only the lines/parameters that are absolutely required to reproduce the bug.
    • Do not run Caddy inside containers.
    • Run Caddy manually in your terminal; do not use systemd or other init systems.
    • If making HTTP requests, avoid web browsers. Use a simpler HTTP client instead, like curl.
    • Do not redact any information from your config (except credentials). Domain names are public knowledge and often necessary for quick resolution of an issue!
    • Note that ignoring this advice may result in delays, or even in your issue being closed. 😞 Only actionable issues are kept open, and if there is not enough information or clarity to reproduce the bug, then the report is not actionable.

Example of a tutorial:

Create a config file:
{ ... }

Open terminal and run Caddy:

$ caddy ...

Make an HTTP request:

$ curl ...

Notice that the result is ___ but it should be ___.

@mholt mholt added the bug 🐞 Something isn't working label Jul 13, 2023
@mholt mholt added this to the v2.7.0 milestone Jul 13, 2023
@mholt mholt added the needs info 📭 Requires more information label Jul 14, 2023
@mholt
Copy link
Member

mholt commented Jul 14, 2023

@text01001 What is your config, at least?

@text01001
Copy link
Author

Sorry for the long wait, I re-edited the issue with more details

@francislavoie
Copy link
Member

Can you trigger the problem without the plugin?

@text01001
Copy link
Author

No plug-in will not panic, but caddy commit 7ceef91 The same compilation method and startup will not panic, everything is normal

@francislavoie
Copy link
Member

Thanks @text01001 I can replicate the problem and I understand what's wrong. But fixing it correctly is complicated, I think @mholt will need to find a solution.

@mholt
Copy link
Member

mholt commented Jul 18, 2023

Thanks -- dang... of course, my TODO in the code turns out to be prophetic.

I'll work on this this week.

@mholt
Copy link
Member

mholt commented Jul 21, 2023

I think I have a fix for this, but am verifying that it works in conjunction with another patch coming up.

@mholt mholt removed the needs info 📭 Requires more information label Jul 21, 2023
mholt added a commit that referenced this issue Jul 21, 2023
Separate currentCtxMu to protect currentCtx, and a new
rawCfgMu to protect rawCfg and synchronize loads.
@mholt mholt closed this as completed in b51dc5d Jul 21, 2023
@mholt
Copy link
Member

mholt commented Jul 21, 2023

@text01001 Could you please try the patch at ---

nvm Francis already confirmed it 😆

Still please try it out 🙃

@text01001
Copy link
Author

Thanks for the fix.
After testing(b51dc5d), starting caddy will not panic. But the caddy-trojan plugin doesn't work, I don't know if it's a caddy or trojan plugin problem.

{"level":"warn","ts":1689976533.7841501,"msg":"unable to determine directory for user configuration; falling back to current directory","error":"neither $XDG_CONFIG_HOME nor $HOME are defined"}
{"level":"info","ts":1689976534.4376004,"msg":"using provided configuration","config_file":"/tmp/caddy/Caddyfile","config_adapter":""}
{"level":"warn","ts":1689976534.4769194,"msg":"Caddyfile input is not formatted; run 'caddy fmt --overwrite' to fix inconsistencies","adapter":"caddyfile","file":"/tmp/caddy/Caddyfile","line":22}
{"level":"info","ts":1689976534.4823287,"msg":"redirected default logger","from":"stderr","to":"/tmp/caddy/caddy_log.txt"}
Error: loading initial config: loading new config: loading http app module: provision http: loading listener wrapper modules: position 0: loading module 'trojan': provision caddy.listeners.trojan: listener: trojan is not configured
 endpoint started","address":"localhost:2019","enforce_origin":false,"origins":["//localhost:2019","//[::1]:2019","//127.0.0.1:2019"]}
{"level":"info","ts":1689976534.4964209,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0x3481c20"}
{"level":"info","ts":1689976534.4975605,"logger":"tls.cache.maintenance","msg":"stopped background certificate maintenance","cache":"0x3481c20"}

@francislavoie
Copy link
Member

provision caddy.listeners.trojan: listener: trojan is not configured

I think this means your server name is not correct and doesn't match any servers in your config.

In other words, :88 { and servers 127.0.0.1:88 { are a mismatch. Change it to servers :88 { and it should work.

See the docs https://caddyserver.com/docs/caddyfile/options#server-options it explains the servers naming rules.

@text01001
Copy link
Author

text01001 commented Jul 21, 2023

provision caddy.listeners.trojan: listener: trojan is not configured

I think this means your server name is not correct and doesn't match any servers in your config.

In other words, :88 { and servers 127.0.0.1:88 { are a mismatch. Change it to servers :88 { and it should work.

See the docs https://caddyserver.com/docs/caddyfile/options#server-options it explains the servers naming rules.

No, after testing, when I apply it in the production environment, the test website cannot be accessed.

{
	admin off
	log {
		output file /tmp/caddy/caddy_log.txt
		level INFO
	}
	trojan {
		caddy
		no_proxy
		users 1234
	}
	servers 127.0.0.1:88 {
		listener_wrappers {
			proxy_protocol
			trojan
		}
		protocols h1 h2c
	}
}
:88 {
	bind 127.0.0.1
	route {
		file_server {
			browse
			root /tmp/caddy
		}
	}
}

log:

Error: loading initial config: loading new config: loading http app module: provision http: loading listener wrapper modules: position 1: loading module 'trojan': provision caddy.listeners.trojan: listener: trojan is not configured

I deleted the content related to the trojan plug-in, and this configuration file can work normally. Added trojan plugin content does not work.

{
	admin off
	log {
		output file /tmp/caddy/caddy_log.txt
		level INFO
	}
	servers 127.0.0.1:88 {
		listener_wrappers {
			proxy_protocol
		}
		protocols h1 h2c
	}
}
:88 {
	bind 127.0.0.1
	route {
		file_server {
			browse
			root /tmp/caddy
		}
	}
}

And the old version has always used servers 127.0.0.1:88 without any problems

@text01001
Copy link
Author

provision caddy.listeners.trojan: listener: trojan is not configured

I think this means your server name is not correct and doesn't match any servers in your config.

In other words, :88 { and servers 127.0.0.1:88 { are a mismatch. Change it to servers :88 { and it should work.

See the docs https://caddyserver.com/docs/caddyfile/options#server-options it explains the servers naming rules.

I have used bind 127.0.0.1, so the writing of servers 127.0.0.1:88 is correct

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