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

Why panic? fmt.Sprintf("%d@%d@%d",v1,v2,v3) #39587

Closed
lovei opened this issue Jun 15, 2020 · 14 comments
Closed

Why panic? fmt.Sprintf("%d@%d@%d",v1,v2,v3) #39587

lovei opened this issue Jun 15, 2020 · 14 comments

Comments

@lovei
Copy link

@lovei lovei commented Jun 15, 2020

What version of Go are you using (go version)?

go1.14.2 linux/amd64

Does this issue reproduce with the latest release?

My server happened once yesterday

What did you do?

runtime error: invalid memory address or nil pointer dereference

/var/jenkins_home/go/src/runtime/panic.go:969 +0x166 fmt.(*buffer).writeString(...)

/var/jenkins_home/go/src/fmt/print.go:82 fmt.(*fmt).padString(0xc00432b220, 0x0, 0xe)

/var/jenkins_home/go/src/fmt/format.go:110 +0x8c fmt.(*fmt).fmtS(0xc00432b220, 0x0, 0xe)

/var/jenkins_home/go/src/fmt/format.go:359 +0x61 fmt.(*pp).fmtString(0xc00432b1e0, 0x0, 0xe, 0x73)

/var/jenkins_home/go/src/fmt/print.go:450 +0x1ba fmt.(*pp).printArg(0xc00432b1e0, 0x2365440, 0xc008a8c570, 0x73)

/var/jenkins_home/go/src/fmt/print.go:698 +0x843 fmt.(*pp).doPrintf(0xc00432b1e0, 0x26a7bb7, 0x1d, 0xc000d1f278, 0xa, 0xa)

/var/jenkins_home/go/src/fmt/print.go:1030 +0x15a fmt.Sprintf(0x26a7bb7, 0x1d, 0xc0009c1278, 0xa, 0xa, 0x2738001, 0x10000c00432b1e0) /var/jenkins_home/go/src/fmt/print.go:219 +0x66

@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 15, 2020

Thank you for reporting this issue. Before we can investigate can you please do one or more of the following

  • post the complete stack trace you received.
  • provide a sample program that someone outside your environment can use to reproduce the issue.
@randall77
Copy link
Contributor

@randall77 randall77 commented Jun 15, 2020

/var/jenkins_home/go/src/fmt/format.go:359 +0x61 fmt.(*pp).fmtString(0xc00432b1e0, 0x0, 0xe, 0x73)

Something is wrong with one of the strings that you're printing. It has a nonzero length (0xe) but its data pointer is 0x0. That can't happen in pure Go. Are you using unsafe? cgo? Does the race detector pass?

Find out where that string came from. That's where the bug is.

Looks superficially similar to #39495 .

@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 15, 2020

Have you tried running your program under the race detector? See https://blog.golang.org/race-detector .

@lovei
Copy link
Author

@lovei lovei commented Jun 15, 2020

go test -race xxx_test.go this works ok
Not using unsafe or cgo
This can hardly reproduce the problem
It may be difficult to explain, my server has been running for a long time, and has appeared once so far

@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 15, 2020

@lovei it is possible that your test coverage do not exercise the race condition. Can you build your server process using the -race flag.

@lovei
Copy link
Author

@lovei lovei commented Jun 15, 2020

Yes, I used the -race flag to build the server code (it took about 10 minutes to run) and called the method many times, but this does not seem to print WARNING: DATA RACE about fmt.Sprintf).

I can't understand why panic at here?
the parameter s can not be nil, but buffer is not my control.

/var/jenkins_home/go/src/runtime/panic.go:969 +0x166 fmt.(*buffer).writeString(...)

func (b *buffer) writeString(s string) {
*b = append(*b, s...)
}
@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 15, 2020

@lovei are you able to provide the full stack trace?

@lovei
Copy link
Author

@lovei lovei commented Jun 15, 2020

@davecheney recover.txt
My server used recovery, it only reported this to me, sorry no more logs.

@davecheney
Copy link
Contributor

@davecheney davecheney commented Jun 15, 2020

@lovei thank you for the stack trace. Are you 100% sure you have deployed your -race build binary to your server and subjected it to the same traffic?

@lovei
Copy link
Author

@lovei lovei commented Jun 15, 2020

@lovei thank you for the stack trace. Are you 100% sure you have deployed your -race build binary to your server and subjected it to the same traffic?

sorry, not the same traffic, i just tested it on my pc with -race.

@undom
Copy link
Contributor

@undom undom commented Sep 8, 2020

@lovei thank you for the stack trace. Are you 100% sure you have deployed your -race build binary to your server and subjected it to the same traffic?

same case, I recurring this problem, because of shared memory

package main

import (
   "fmt"
   "time"
)

func main() {

   fullPath:= "init"

   go func() {
      for {
         request(&fullPath)
      }
   }()

   for {
      fullPath = ""
      time.Sleep(10 * time.Nanosecond)
      fullPath = "/test/test/test"
      time.Sleep(10 * time.Nanosecond)
   }

}

func request (c *string) {
   println(fmt.Sprintf("fullPath: %s", *c))
}

type context struct {
   fullPath string
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x105c706]

goroutine 18 [running]:
fmt.(*buffer).writeString(...)
        /usr/local/go/src/fmt/print.go:82
fmt.(*fmt).padString(0xc000090040, 0x0, 0xf)
        /usr/local/go/src/fmt/format.go:110 +0x8c
fmt.(*fmt).fmtS(0xc000090040, 0x0, 0xf)
        /usr/local/go/src/fmt/format.go:359 +0x61
fmt.(*pp).fmtString(0xc000090000, 0x0, 0xf, 0xc000000073)
        /usr/local/go/src/fmt/print.go:450 +0x1ba
fmt.(*pp).printArg(0xc000090000, 0x10acd20, 0xc000094d90, 0x73)
        /usr/local/go/src/fmt/print.go:698 +0x843
fmt.(*pp).doPrintf(0xc000090000, 0x10cf552, 0xc, 0xc00006cfb8, 0x1, 0x1)
        /usr/local/go/src/fmt/print.go:1030 +0x15a
fmt.Sprintf(0x10cf552, 0xc, 0xc00006cfb8, 0x1, 0x1, 0xc000092ee0, 0xa)
        /usr/local/go/src/fmt/print.go:219 +0x66
main.request(...)
        /Users/sgcx057/GolandProjects/my-test/main.go:32
main.main.func1(0xc000108040)
        /Users/sgcx057/GolandProjects/my-test/main.go:15 +0x8e
created by main.main
        /Users/sgcx057/GolandProjects/my-test/main.go:13 +0x6a
@davecheney
Copy link
Contributor

@davecheney davecheney commented Sep 8, 2020

@fxxkingNoob the program you supplied has a data race.

Have you tried running your program under the race detector? See https://blog.golang.org/race-detector .

@undom
Copy link
Contributor

@undom undom commented Sep 8, 2020

@fxxkingNoob the program you supplied has a data race.

Have you tried running your program under the race detector? See https://blog.golang.org/race-detector .

Of course it has data race.
Im telling the guys who has same issue, that's why fmt.Sprintf() throws panic.

@davecheney
Copy link
Contributor

@davecheney davecheney commented Sep 8, 2020

Ok, thank you. I think this issue can be closed.

@davecheney davecheney closed this Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.