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

Http node client requests response body contains /r/n (especially WCF Exceptions) causes ECONNRESET #2440

Closed
arnolddozsa opened this issue Jan 23, 2020 · 3 comments

Comments

@arnolddozsa
Copy link

  • Version:
    v8.16.2

  • Platform:Linux raspberrypi 4.19.66-v7+ Switch ClosureLinter to other linter. node#1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux

  • Subsystem: http requests

  • Windows version:
    Windows Server 2012

  • ** Host**:
    IIS 8.5
    WCF Application .NET 4.5

I ran into a problem.
Make Http request from nodejs client to a Windows Server 2012 IIS with WCF hosted (self made code).

pasted only the method on nodejs which does the job.

There is properties in the object where serviceUrl and others are definied.

post(options, parameters = undefined){
    
     var postData = "";
     var instance = this;
     var opts = {
        hostname: this.serviceUrl,
        port: this.port,
        path: "/",
        method: 'POST', 
        headers: {
            'Content-Type': 'application/json',
            'Cookie': this.cookieJar,
        }
      
    };

    var headers = opts.headers;

    options = Object.assign(opts, options);

    options.headers = Object.assign(headers, options.headers);

    
    if(parameters !== undefined){
        postData = JSON.stringify(parameters)
    }

    


    var request = http.request(options);

    for(var key in options.headers){
        request.setHeader(key, options.headers[key]);
    }


    return new Promise((resolve, reject) => {
        try{
            if(parameters !== undefined){
                request.write(postData, "utf-8");
            }

            request.end();

            
            request.on('response', function (response) {
                if(response.headers["set-cookie"] != undefined){
                    instance.cookieJar = response.headers["set-cookie"];
                }
                
                var statusCode = response.statusCode;
                if (!((200 <= statusCode && statusCode < 300))) {
                    reject(new HttpRequestError(`Response statusCode: ${response.statusCode}, responseText: ${response.statusMessage}`, request, response));
                    return;
                }


                var data = "";

                response.setEncoding('utf8');  
                response.on('data', function (chunk) {
                    data += chunk;
                
                });

                response.on("end", function(){
                    if (response.headers["content-type"] && ~response.headers["content-type"].toLocaleLowerCase().indexOf("application/json")) {
                        try {
                            data = JSON.parse(data);
                        } catch (error) {
                            reject(error);
                            return;
                        }
                    }
                    

                    resolve(data);

                });
                


            });

            request.on('error', function (err) {
                reject(err);
            });
        }catch(err){
            reject(err);
        }
    });
}

}

Lets say this WCF endpoint is called previously.

public Boolean Log(List<Log> logs, Truck truck)
    {
    try
        {
          ... do some stuff
            
        }
        catch (Exception ex)
        {
            var msg = ex.Message;
            msg = msg.Replace(System.Environment.NewLine, "");
            var e = new Exception(msg);


            throw e;
        }


        return true;
    }

When i do not replacing System.Environment.Newline in the exceptions Message then on the nodejs side raises ECONNRESET and cannot get the exception details thrown in WCF.

When i do replace the System.Environment.Newline in the exceptions Message the nodejs got the statuscode 500, got the exception raised in WCF as responseBody formatted as expected.
(Works as need to work in this situation)

Tested these two behaviors. And with these information you can reproduce it

@bnoordhuis bnoordhuis transferred this issue from nodejs/node Jan 24, 2020
@bnoordhuis
Copy link
Member

I'm moving this to nodejs/help because it's almost certainly an issue with the server sending back a malformed response.

@gireeshpunathil
Copy link
Member

@arnolddozsa - is this still an issue?

@gireeshpunathil
Copy link
Member

inactive, closing. feel free to re-open if it is outstanding

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

No branches or pull requests

3 participants