-
Notifications
You must be signed in to change notification settings - Fork 48
Deep recursion in completion callback #28
Comments
Can you provide a testcase or some example code that shows the problem occurring? |
The worse aspect is that this calls the done-cb before the queued write has actually finished! This needs to be passed along the stream, that's the whole point. Also the method looks inefficient. It calls |
@aleksey-mashanov presumably you're referring to the fact that its an And yes - as @helje5 says, it looks like its not actually associated with the write (which is async...) |
I see no reason to use The main point of this issue is to raise discussion about sync/async API and how to achieve both. |
A P.S.: Sorry for hijacking this PR, that really wasn't appropriate. If this is about sync/async again - that topic was also discussed on the list already. Maybe it should a) state its purpose better and b) link to the mailing list archives for context. I don't see how this conflicts w/ synchronous use, a synchronous call would directly invoke the CB (funny enough - it is precisely what the current implementation gets wrong :-) ). In fact the callback is of little use in a synchronous implementation because by definition that always returns immediately ... |
Prove this with a code snippet plz. Lets imagine what we have an array of strings and we want to write it to the body.
Yes. And this is the problem itself: deep recursion. writeBody then callback then writeBody then callback ... and then out of the stack. Synchronous code must not use callbacks. |
There should be two |
@aleksey-mashanov the concurrency model that exists for Swift is async based. What would be the driver for there to be support for both sync and async APIs? |
Wrt DispatchData, Sync works just fine, I already did a proof of concept implementation for the 1st revision of the proposal (mod_swift), I don't think anything relevant has changed. W/ a sync implementation the write returns when it is done, there is simply no reason to use the callback to schedule subsequent writes. (only if you actually want the recursion 🤓)
Hm? Today no concurrency model for Swift exists at all. Only last week or so a first proposal for a maybe-Swift-5-one has been published by Chris Lattner ;-)
Well, because there are going to by synchronous implementations :-) But the current proposal should be OK for that - as far as I can see. Maybe I should redo the mod_swift proof of concept. |
@seabaylea Swift itself has no concurrency model. It can be used with sync and async both. Personally in general I prefer sync because it is simpler to maintain large codebase but I use async for tasks there it suits better for some reasons. The model provided by Apple in their Foundation and Dispatch frameworks can suit well to client side developers who want to write a little server side code but not to server side developers who want to use Swift in the way they used to with other popular server side languages. |
Complete snippet plz. I still don't understand. To be clear, |
I put comments from @helje5 into two other issues so we can track them explicitly. They're both valid points, so I explained why I did what I did, and I'm happy to discuss better implementations. But I didn't want those topics to get lost in this issue. |
In theory with current implementation of
HTTPStreamingParser
it is possible to run out of the stack. This problem can occur if a long chain of callback receiving methods (i.e.writeBody
) is called. To solve this completion callback should never be called before method returns.Because of this problem it looks like two different APIs for sync/async should exist. Right now I see no solution to perform sync operations via async API.
The text was updated successfully, but these errors were encountered: