BurntSushi / xgb

The X Go Binding is a low-level API to communicate with the X server. It is modeled on XCB and supports many X extensions.
Other
489 stars 75 forks source link

Maximum number of clients reached #40

Open co60ca opened 7 years ago

co60ca commented 7 years ago

If you open over 200 connections and close them you will get this error:

x protocol authentication refused: Maximum number of clients reached

func TestXGB (t *testing.T) {                                                   
  for i := 0; i < 1000; i++ {                                                   
    t.Log("log", i, '/', 1000)                                                  
    c, err := xgb.NewConn()                                                     
    if err != nil {                                                             
      t.Fatal("Bad things happened", err)                                       
    }                                                                           
    defer c.Close()                                                             
  }                                                                             
}

This seems to be valid application so I'm not sure what is going wrong here.

BurntSushi commented 7 years ago

Why do you want to have 200 simultaneous X connections? What problem are you trying to solve?

The error returned appears to be coming from X itself?

On Sep 9, 2017 8:59 PM, "Brad Kennedy" notifications@github.com wrote:

If you open over 200 connections and close them you will get this error:

x protocol authentication refused: Maximum number of clients reached

func TestXGB (t *testing.T) { for i := 0; i < 1000; i++ { t.Log("log", i, '/', 1000) c, err := xgb.NewConn() if err != nil { t.Fatal("Bad things happened", err) } defer c.Close() } }

This seems to be valid application so I'm not sure what is going wrong here.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/BurntSushi/xgb/issues/40, or mute the thread https://github.com/notifications/unsubscribe-auth/AAb34uy3rxQCC84Ug-xaAFVoci152NOuks5sgzSFgaJpZM4PSKtg .

co60ca commented 7 years ago

To be more clear, we are closing the connection each time, only one should be active.

func TestXGB (t *testing.T) {                                                   
  for i := 0; i < 1000; i++ {                                                   
    t.Log("log", i, '/', 1000)                                                  
    c, err := xgb.NewConn()                                                     
    if err != nil {                                                             
      t.Fatal("Bad things happened", err)                                       
    }                                                                           
    c.Close()                                                                   
  }                                                                             
}   

Rewrote and tested without defer to be more clear. Closing the connection should free resources correct? So creating and closing the connection 200+ times shouldn't have a resource leak.

I'm trying to help assist in fixing a bug in someone else's project utilizing this codebase. See: https://github.com/vova616/screenshot

I wrote a workaround for their library but I would like to assist in fixing it here as well.

To be clear, creating 250 connections in less than a second isn't my use case, but shows the issue.

Also I misunderstood how defer worked so there might have been an error in the original test case, however it shows the same result before and after, furthering my point.

BurntSushi commented 7 years ago

Right, the original test case did indeed open many connections simultaneously since defer applies to the scope of the enclosing function.

Your second test case it's more interesting and I agree it should work. I still think it's a little odd to be opening and closing connections instead of keeping one open, but you'll have to dig into this to figure out the problem. IIRC, someone had reported this issue before, so you might have luck looking at past issues.