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

Maximum call stack size exceeded #189

Closed
armpogart opened this issue Jan 22, 2020 · 7 comments
Closed

Maximum call stack size exceeded #189

armpogart opened this issue Jan 22, 2020 · 7 comments

Comments

@armpogart
Copy link

I was finally debugging #173 issue, and I think I know the reason why that happens, but now when trying to use the library in pure node environment I get call stack size exceeded issue from recursion and I can't understand why that happens. Here is all the info that I could find, maybe you will be able to debug it further:

Node version: v12.14.1
package.json file:

{
  "name": "webdav-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "dependencies": {
    "webdav": "^2.10.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

index.js file:

const { createClient } = require('webdav');
const { createReadStream } = require('fs');

const client = createClient(
    'https://url/dav',
    {
        username: 'username',
        password: 'password',
        digest: true
    }
);

const readStream = createReadStream('./some_image.jpg');
const writeStream = client.createWriteStream(`/some_path/some_image.jpg`, {
    overwrite: true,
});
readStream.pipe(writeStream);

and I get:

RangeError: Maximum call stack size exceeded
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:44:25)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (webdav-test\node_modules\merge\merge.js:65:28)
    at Function.Public.clone (node_modules\merge\merge.js:65:28)
    at Function.Public.clone (node_modules\merge\merge.js:65:28)

I'm sure that authentication works, I've tried client.getDirectoryContents("/some_path/"); and it works and lists all items in directory. The image is there and I'm able to read it and write to other file directly using streams. I've also tried to attach error event handlers to both streams, and there is no any error there.
As far as debugging goes, you can see that the issue is in one of your dependencies merge on line 44 the method Public.clone which on line 65 again calls itself so recursion happens and maximum call stack size is exceeded. While debugging with breakpoint set there I could see infinitely (not sure as I resumed my app maybe 100 times, before giving up) times app pausing on that breakpoint.
Not sure what else I can do. Maybe the node version has problems?

@armpogart
Copy link
Author

I was able to isolate the problem. I have found all cases where the merge was called and as soon as I've commented the following lines and replaced them with:

requestOptions.headers = {
    Authorization: generateDigestAuthHeader(requestOptions, _digest)
}

as I wasn't using any additional options.
Now everything works, but I get zero length file on dav host, maybe the same issue as #181, but the host uses SabreDav server.

@perry-mitchell
Copy link
Owner

Thanks a lot for the write-up @armpogart! Seems that the merge package isn't maintained terribly regularly, in terms of issues. The cloning system it uses looks to be at fault like you said, so I'll perhaps use something smaller in this library without the need for the 3rd-party one.

I don't use any services with Digest auth, so I'll let you know once I've updated this to confirm that it works. Thanks!

@perry-mitchell
Copy link
Owner

I've removed the merge dependency in #190 - Will release shortly.

@armpogart
Copy link
Author

armpogart commented Jan 25, 2020

@perry-mitchell Thanks for a quick reply and a fix to the merge issue. I'll try to test the solution as quick as possible.

Still the #181 issue with zero length remains. I'll try to dig deeper to find the reason for that behavior and finally resolve the problem in #173.

@perry-mitchell
Copy link
Owner

Released in 2.10.2 @armpogart

@perry-mitchell
Copy link
Owner

@armpogart Did you yet have a chance to test the update?

As an aside: I've now released version 3.0.0 - both it and 2.x have the fix I mentioned.

@armpogart
Copy link
Author

@perry-mitchell I've tested the fix with both versions, and now everything works, thanks!

P.S. I mean Maximum call stack size exceeded issue is resolved, but I still get zero-length file.

Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants