Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot switch to old mode now. #23

Closed
fabdrol opened this issue Jun 16, 2014 · 14 comments
Closed

Error: Cannot switch to old mode now. #23

fabdrol opened this issue Jun 16, 2014 · 14 comments
Assignees
Labels

Comments

@fabdrol
Copy link

fabdrol commented Jun 16, 2014

I'm using https://github.com/balderdashy/skipper to upload files in a sails js application, which gave the error Error: Cannot switch to old mode now. After some digging, I found out that the error is fixed by commenting out line #33 in stream-utils/raw-body/index.js. It seems to be related to this issue: https://github.com/balderdashy/skipper/issues/10.

While I'm convinced this is an issue related to balderdashy/skipper specifically, I'm posting this here anyway - maybe you guys can shed some light on this issue.

Cheers, Fabian

@jonathanong
Copy link
Contributor

you're probably using the stream somewhere else as well, which you shouldn't be doing (except for maybe pipes)

@dougwilson
Copy link
Member

@fabdrol can you post what "line 33" refers to? Right is it is if (options.length != null && !isNaN(options.length)), but I don't think that is what you are referring to in this case.

@fabdrol
Copy link
Author

fabdrol commented Jun 16, 2014

Sorry, it's line 40/41 in the code in the repo:

 if (typeof stream.pause === 'function')
      stream.pause()

@dougwilson
Copy link
Member

I think I see the problem. It looks like skipper is setting the steam into the "new mode" and then passing it to this module, which cannot then call pause() since that is an old-mode method. Basically the issue boils down to you cannot pass in streams that have been switched into the "new mode" in node.js 0.10, since this module supports node.js 0.8.

@dougwilson
Copy link
Member

Actually, sorry, re-opening.

@dougwilson dougwilson reopened this Jun 16, 2014
@dougwilson
Copy link
Member

So what we need to do here is determine if the stream is in old mode or not. If it is in old mode, we need to pause() is on error, but if it is in new mode, we do not have to do anything but remove the data listeners because it'll automatically pause.

@dougwilson dougwilson added the bug label Jun 16, 2014
@dougwilson dougwilson self-assigned this Jun 16, 2014
@dougwilson
Copy link
Member

@fabdrol I am working on a fix. It doesn't look like skipper is using raw-body directly, but rather an old connect that is indirectly using this module, so even when I fix this here, skipper will need to do a lot of updates to pull in the fix.

@dougwilson
Copy link
Member

Nevermind, I was wrong on why the error is cause. It's because req is already being piped somewhere else before it gets handed to this module. It is an error in skipper; I will post it over there. We could certainly have a better error come out of this module, though.

@fabdrol
Copy link
Author

fabdrol commented Jun 16, 2014

@dougwilson hmm, okay. Good to know some background. Is the issue specific to the older version, or would a newer version have the same problems?

@dougwilson
Copy link
Member

All versions have the same problem. It's an issue with now skipper is trying to pipe the request multiple times if the request did not come in with a known Content-Type header.

@fabdrol
Copy link
Author

fabdrol commented Jun 16, 2014

Ps, if this is not an issue with this module but with skipper, we can close this right?

@dougwilson
Copy link
Member

@fabdrol I was going to close it when I made this module provide a better response to the situation, but we can close it regardless, because yes, the issue you reported is cause by what skipper is doing and needs to be fixed there regardless.

@fabdrol
Copy link
Author

fabdrol commented Jun 16, 2014

@dougwilson okay, thanks for your help anyway!

@dougwilson
Copy link
Member

No problem. I just posted a possible fix to skipper on that thread you referenced earlier, by the way. I didn't actually test to confirm that it works, but I'm pretty sure it will.

@stream-utils stream-utils locked and limited conversation to collaborators Jul 11, 2014
dougwilson added a commit that referenced this issue Jul 20, 2014
dougwilson added a commit that referenced this issue Jul 20, 2014
dougwilson added a commit that referenced this issue Jul 21, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants