8000 AdjacencyMap may cause panic · Issue #102 · dominikbraun/graph · GitHub
[go: up one dir, main page]

Skip to content

AdjacencyMap may cause panic #102

Open

Description

@liuxiaomeiG

Concurrent calls to AddVertex, AddEdge, and AdjacencyMap redundantly panic.

panic: assignment to entry in nil map

goroutine 1996 [running]:
github.com/dominikbraun/graph.(*undirected[...]).AdjacencyMap(0xc0009542c0?)
	github.com/dominikbraun/graph@v0.16.2/undirected.go:167 +0x225

image

ListVertices and ListEdges directly occur AddVertex and AddEdge will cause this problem

Activity

  1. davidovich commented on Oct 12, 2023

    @davidovich

    We have experienced this also in a non concurrent environment. PredecessorMap() is guarded against nil access, I wonder if it was intended to leave it out in AdjacencyMap(). If not, would you accept a PR to add an initialization if the edge.Target is not found ?

  2. dominikbraun commented on Oct 13, 2023

    @dominikbraun
    Owner

    @davidovich Yes. AdjacencyMap should behave exactly as PredecessorMap since these functions do the same thing but complement each other.

  3. added a commit that references this issue on Oct 13, 2023
    391493f
  4. davidovich commented on Oct 13, 2023

    @davidovich

    While investigating this issue, it appeared to me that the code is correct on assuming the presence of a vertex, hence it would be, IMHO, a bad fix to just initialize the map on an un-existing source vertex because that would create a degenerate edge.

    In our implementation of the store interface, we hit a panic because the store was returning edges with vertices that did not exist. So I went and opened a PR for reporting that error instead of panicking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0