Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1373

stack overflow when assigning values to a map

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Works as Designed
    • Icon: Major - P3 Major - P3
    • None
    • 1.1.2
    • BSON, CRUD
    • None
    • Ubuntu 16.04, Intel Core i5, MongoDB version 4.2

    Description

       

      Running the following snippet:

       

      package main
       
      import (
         "context"
         "fmt"
         "log"
         "time"
       
         "go.mongodb.org/mongo-driver/mongo"
         "go.mongodb.org/mongo-driver/mongo/options"
      )
       
      type User struct {
         ID        string
         Name      string
         Followers map[string]*User
         Friends   map[string]*User
      }
       
      func main() {
       
         ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
         defer cancel()
       
         client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
       
         err = client.Ping(ctx, nil)
         if err != nil {
            log.Fatal("could not connect")
         }
       
         coll := client.Database("testing").Collection("users")
       
         ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
         defer cancel()
       
         u1 := &User{ID: "24", Name: "Test1", Followers: map[string]*User{}, Friends: map[string]*User{}}
         u2 := &User{ID: "25", Name: "Test2", Followers: map[string]*User{}, Friends: map[string]*User{}}
       
         u1.Friends[u2.ID] = u2
         u2.Followers[u1.ID] = u1
         
         // uncommenting the next line and commenting out the two above gives the same behavior i.e. assigning to self
         //u1.Followers[u1.ID] = u1 
       
         res, err := coll.InsertOne(ctx, u1)
         if err != nil {
            fmt.Println("error:", err)
         }
         fmt.Println(res.InsertedID)
      }

       

       gives the following error:

       

      runtime: goroutine stack exceeds 1000000000-byte limitruntime: goroutine stack exceeds 1000000000-byte limitfatal error: stack overflow
      

       

       

       

       

      Attachments

        Activity

          People

            isabella.siu@mongodb.com Isabella Siu (Inactive)
            jimiolaniyan@gmail.com Folajimi Sparse
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: