fix(streaming): validate the stream descriptor before using it - #741
Conversation
newStream stored the descriptor and read its required fields straight away, so a response missing refreshActiveSessionInterval, sessionToken or dataFeedURL panicked inside NewStream. A zero or negative interval reached time.NewTicker and panicked there instead. The generated Validate method already checks every required field, so it is called before the handle is built. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
Thanks for picking this up. Returning an error from 1. An interval of 1 still panics
Suggestion: calculate the refresh period once, in 2. The test fixture is invalid, so each case fails for the wrong reason
Every case therefore fails on that same error before it ever reaches the field it's named after. The 3.
|
…e refresh period safely Replace stream.Validate with explicit nil checks on dataFeedURL, sessionToken, sessionToken.token and refreshActiveSessionInterval, the only fields newStream, open and url dereference. Validate also requires refreshActiveSessionURL and sessionToken.expiration, neither of which is read, so descriptors that work on main today would have been rejected. Work the refresh period out once, in time.Duration, and check the result rather than the raw interval. The old nine tenths integer arithmetic gave a period of 0 for an interval of 1, which panics time.NewTicker, and overflowed to a negative period for very large values. Pass the checked period into maintainSession so the value that was checked is the value that gets used. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
All four confirmed and fixed in fe182bb. The fixture was broken exactly as you said: every case failed on On the period, one addition to your suggestion.
To your question: defensive, not observed. I read the pointer dereferences in Happy to open the |
|
Ack. Thanks for the fix! I am going to add a follow up PR to address some other issues. |
MainAvailableStreamV2has four fields the spec marks required, and the generated model renders all four as pointers.newStreamtakes the descriptor thatListAvailableStreamsOAuth2returned and goes straight to reading them, so anything the API leaves out is a nil dereference rather than an error. Followingexamples/falcon_event_stream, a descriptor with norefreshActiveSessionIntervalpanics here:sessionTokenanddataFeedURLgo the same way a little later, and an interval of 0 gets past a nil check only to panic insidetime.NewTickerwith a non-positive interval.The model already carries a
Validatethat checks exactly those fields, sonewStreamnow calls it and returns the error, with a separate check for the interval since being present is not the same as being usable. Added a table test over the four shapes plus a nil descriptor, which panics on main and passes now.