Ticket #740 (closed Problem: fixed)
Bug resulting in too many internal type references
| Reported by: | seth | Owned by: | jsiwek |
|---|---|---|---|
| Priority: | Normal | Milestone: | |
| Component: | Bro | Version: | |
| Keywords: | Cc: |
Description
There is a hard limit to how many references Bro will create for a type or value (INT_MAX) and we are using a function incorrectly leading to termination after long uptimes.
There are a few places (for example strings.bif:132) where the internal_type function is called to get a reference to the type for a Bro script level defined type. Unfortunately when internal_type is called, it in turn calls lookup_ID (Var.cc:486 leading to Scope.cc:115) which looks up the type, adds an additional reference to it and returns it. The code that called internal_type never Unrefs the value. Eventually Obj.h:207 causes a shutdown when INT_MAX references are created to the type.
I'm thinking we should just lookup the type a single time at startup along with all of the other Bro defined types in NetVar?.cc and reuse the value after that so we one reference it a single time. It's more consistent with how the internal_type function is called for other cases.
Change History
comment:2 follow-up: ↓ 3 Changed 5 months ago by robin
This sounds like a plain ref counting bug to me. The caller should
unref once it doesn't need the type anymore. Were you able to
understand which caller isn't doing it? It doesn't need to be the on
the stack backtrace (and from a quick look, it isn't).
I'm thinking we should just lookup the type a single time at startup along with all of the other Bro defined types in NetVar??.cc and reuse the value after that so > we one reference it a single time.
That won't help as anybody using a a type would still need to ref it (and thus also unref).
It's more consistent with how the internal_type function is called for other cases.
Why would that be more consistent?
comment:2 follow-up: ↓ 3 Changed 5 months ago by seth
This sounds like a plain ref counting bug to me. The caller should
unref once it doesn't need the type anymore. Were you able to
understand which caller isn't doing it? It doesn't need to be the on
the stack backtrace (and from a quick look, it isn't).
There are only a few places outside of NetVar?.cc that even call internal_type which is why I made the consistency comment. You can find everywhere that causes this ref counting problem with a quick grep since there aren't that many, especially if you count out the stuff in NetVar?.cc.
And I caused this bug (/me ducks).
comment:4 Changed 5 months ago by seth
So where's the unref missing?
In the do_split function. I'm never saving the returned ref'd pointer from the internal_type call so I couldn't unref it (I didn't realize it was adding a reference to the value). I think it should just be moved to NetVar?.cc though.
comment:7 Changed 5 months ago by jsiwek
- Status changed from assigned to closed
- Resolution set to fixed
Here's a backtrace....