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

cmd/cover: panic: overlapping edits #23927

Closed
Cosby86 opened this issue Feb 19, 2018 · 16 comments
Closed

cmd/cover: panic: overlapping edits #23927

Cosby86 opened this issue Feb 19, 2018 · 16 comments
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge release-blocker
Milestone

Comments

@Cosby86
Copy link

Cosby86 commented Feb 19, 2018

Hello all with the latest RC if i run tests all is ok, if I run them with coverage I run into this error:

cover poc/all_test
panic: overlapping edits: [4371,4375)->"", [4372,4372)->"_cover_atomic_.AddUint32(&GoCover_2_646536633930623366336461.Count[26], 1);"

goroutine 1 [running]:
cmd/internal/edit.(*Buffer).Bytes(0xc0421223c0, 0xc0420421e0, 0x63b4a0, 0xc0420ee580)
	C:/workdir/go/src/cmd/internal/edit/edit.go:79 +0x51c
main.annotate(0xc042044060, 0x53)
	C:/workdir/go/src/cmd/cover/cover.go:332 +0x46f
main.main()
	C:/workdir/go/src/cmd/cover/cover.go:88 +0x187 ```
@odeke-em
Copy link
Member

/cc @ianlancetaylor

@ianlancetaylor
Copy link
Contributor

Can you tell us how to recreate the problem?

@ianlancetaylor ianlancetaylor changed the title Panic: overlapping on test with coverage cmd/cover: panic: overlapping edits Feb 19, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.10.1 milestone Feb 19, 2018
@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker labels Feb 19, 2018
@Cosby86
Copy link
Author

Cosby86 commented Feb 19, 2018

Actually i have 340 packages with tests and only one is having this issue. It seems the file is not different from the others. I still have to identify what's causing the issue or how to replicate it. I'll let you know very soon.

@Cosby86
Copy link
Author

Cosby86 commented Feb 22, 2018

I worked and found what's causing the issue. I have this function (it is only an example but it's recreating the issue). With the function below I don't have the issue:

func updateItemsChildrenKeys(itemsColl data.PhysicalItemsCollection, items []data.Item, request *command.InternalRequest, reply *command.Reply) errors.Err {
    up := itemsColl.StartUpdate()
    defer up.EndUpdate()

    for _, item := range items {
        _, _ = up.ByKeyForUpdate(item.Key())
        if item.ParentKey() != nil {

        }

    }

    return nil
}

but when I add the else the issue appears:

func updateItemsChildrenKeys(itemsColl data.PhysicalItemsCollection, items []data.Item, request *command.InternalRequest, reply *command.Reply) errors.Err {
    up := itemsColl.StartUpdate()
    defer up.EndUpdate()

    for _, item := range items {
        _, _ = up.ByKeyForUpdate(item.Key())
        if item.ParentKey() != nil {

        }else{
            
        }

    }

    return nil
}

@Cosby86
Copy link
Author

Cosby86 commented Feb 26, 2018

I was able to replicate the issue with this code too:

if len(attributes) > 0{
			if item != nil{
                            //DO SOMETHING
			}
		}else{
                    //DO SOMETHING
		}

@Cosby86
Copy link
Author

Cosby86 commented Feb 26, 2018

with this code works:

if len(attributes) > 0 && item != nil{
  //DO SOMETHING
}
if len(attributes) > 0 && item == nil{
 //DO SOMETHING
}

It seems the issue is in somewhere in the ELSE clause handler

@ianlancetaylor
Copy link
Contributor

Thanks. For clarity, can you show us a complete, self-contained example, along with the commands you use to recreate the problem? That would save time on our end. Thanks.

@Cosby86
Copy link
Author

Cosby86 commented Feb 27, 2018

Atttached .go file and its related tests. It is veri very very very simple but it reproduce the issue. Let me know

test.zip

@ianlancetaylor
Copy link
Contributor

Thanks. The problem only arises because your main.go file has not been through gofmt. If I run gofmt on the file, the problem disappears.

The problem is specifically }else{. If I change that to } else{ (adding a space after the }, as gofmt does) then the problem does not occur.

main.go:

package main

func main(){
	var attributes []string
	var item interface{}

	if len(attributes) > 0{
		if item != nil{
			//DO SOMETHING
		}
	}else{
		//DO SOMETHING
	}
}

main_test.go:

package main

import (
	"testing"
)

func TestMain(t *testing.T) {
	main()
}

go test -cover

# cover _/tmp/x/src/a
panic: overlapping edits: [142,146)->"", [143,143)->"GoCover_0_366235663035346337313436.Count[3] = 1;"

goroutine 1 [running]:
cmd/internal/edit.(*Buffer).Bytes(0xc0000f2c00, 0xc0000f0120, 0x6216a0, 0xc000110300)
	/home/iant/go/src/cmd/internal/edit/edit.go:79 +0x515
main.annotate(0x7ffeec2bb74a, 0x14)
	/home/iant/go/src/cmd/cover/cover.go:332 +0x468
main.main()
	/home/iant/go/src/cmd/cover/cover.go:88 +0x180
FAIL	_/tmp/x/src/a [build failed]

@Cosby86
Copy link
Author

Cosby86 commented Feb 27, 2018

😮 got it

@gopherbot
Copy link

Change https://golang.org/cl/98935 mentions this issue: cmd/cover: don't crash on non-gofmt'ed input

@andybons
Copy link
Member

CL 98935 OK for Go 1.10.1

@andybons andybons added CherryPickApproved Used during the release process for point releases and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 27, 2018
@gopherbot
Copy link

Change https://golang.org/cl/102786 mentions this issue: [release-branch.go1.10] cmd/cover: don't crash on non-gofmt'ed input

gopherbot pushed a commit that referenced this issue Mar 29, 2018
Without the change to cover.go, the new test fails with

panic: overlapping edits: [4946,4950)->"", [4947,4947)->"thisNameMustBeVeryLongToCauseOverflowOfCounterIncrementStatementOntoNextLineForTest.Count[112]++;"

The original code inserts "else{", deletes "else", and then positions
a new block just after the "}" that must come before the "else".
That works on gofmt'ed code, but fails if the code looks like "}else".
When there is no space between the "{" and the "else", the new block
is inserted into a location that we are deleting, leading to the
"overlapping edits" mentioned above.

This CL fixes this case by not deleting the "else" but just using the
one that is already there. That requires adjust the block offset to
come after the "{" that we insert.

Fixes #23927

Change-Id: I40ef592490878765bbce6550ddb439e43ac525b2
Reviewed-on: https://go-review.googlesource.com/98935
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-on: https://go-review.googlesource.com/102786
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
@AgustinBanchio
Copy link

I had this problem with go 1.10.3
Adding the spaces in the else clauses fixed it.
I was testing the coverage with GoLand so it might be their tools aren't updated

@andybons
Copy link
Member

@AgustinBanchio if you test without GoLand can you still reproduce the issue?

@ianlancetaylor
Copy link
Contributor

@AgustinBanchio This problem is fixed in 1.10.1. If you are seeing the exact same problem, then you are most likely running an older version of the toolchain. If you are sure that you are not, then you have found a different problem. Please open a new issue with reproduction instructions. Thanks.

@golang golang locked and limited conversation to collaborators Jun 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CherryPickApproved Used during the release process for point releases FrozenDueToAge release-blocker
Projects
None yet
Development

No branches or pull requests

6 participants