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

Not set Header.Connection if forever option is falsy #1259

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

sacru2red
Copy link

Not set Header.Connection if forever option is falsy

axios hang up

image

I tried simple codes

import axios from 'axios'
import http from 'node:http'
import { createClientAsync, HttpClient } from 'soap'

const address = 'http://cs.ssis.go.kr/indiv/cwoa/ws/interfaces/ERPII589SSI639W20042'
const methodName = 'WbOrg'
const content = {
  [methodName]: {
    item: {
      foo: 'bar',
    },
  },
}

async function main() {
  const axiosInstance = axios.create({
    httpAgent: new http.Agent(),
  })
  const httpClient = new HttpClient({
    request: axiosInstance,
  })
  const soapClient = await createClientAsync(`${address}?wsdl`, {
    // it works if toggle under
    // ref, server is broken. 500 is ok
    httpClient,
  })

  await soapClient.receiveAsync(
    {
      AuthInfo: {
        ComCode: 'C0000006260',
        Password: '3799232',
      },
      Contents: JSON.stringify(content),
    },
    // createClientAsync cannot set forever
    // {
    //   forever: true,
    // },
  )
}

main()

I found connection 'close' can be problematic

current:

  • request GET wsdl
  • response GET
  • request POST
  • hang up (axios throw error, not excute http request)

pr:

  • request GET wsdl
  • response GET
  • request POST
  • response POST

@w666 w666 self-requested a review October 25, 2024 18:48
@w666
Copy link
Collaborator

w666 commented Oct 25, 2024

Hi @sacru2red, what node, axios and soap versions do you use?

I tried your code locally and could not replicate the issue.

@sacru2red
Copy link
Author

@w666
soap version is 1.1.5
node: 22.7

@sacru2red
Copy link
Author

same error: node 20.17, 19.9
not error: node 18.20.4

@sacru2red
Copy link
Author

sacru2red commented Oct 28, 2024

@w666
Copy link
Collaborator

w666 commented Oct 28, 2024

@sacru2red, I still can replicate the problem, it may be env related.
I tried node 20.12 and latest node 20.18 with soap 1.0.5 and axios 1.7.7. I run my test under WSL.

I slightly modified your code to catch and print the error.

import axios from 'axios'
import http from 'node:http'
import { createClientAsync, HttpClient } from 'soap'

const address = 'http://cs.ssis.go.kr/indiv/cwoa/ws/interfaces/ERPII589SSI639W20042'
const methodName = 'WbOrg'
const content = {
    [methodName]: {
        item: {
            foo: 'bar',
        },
    },
}

async function main() {
    const axiosInstance = axios.create({
        httpAgent: new http.Agent(),
    })
    const httpClient = new HttpClient({
        request: axiosInstance,
    })
    const soapClient = await createClientAsync(`${address}?wsdl`, {
        // it works if toggle under
        // ref, server is broken. 500 is ok
        httpClient,
    })

    try {
        await soapClient.receiveAsync(
            {
                AuthInfo: {
                    ComCode: 'C0000006260',
                    Password: '3799232',
                },
                Contents: JSON.stringify(content),
            },
            // createClientAsync cannot set forever
            // {
            //   forever: true,
            // },
        )
    } catch (err) {
        console.error(`ERROR: `, err.message)
    }
}

main()

I always get the following error

ERROR:  soapenv:Receiver: undefined: [Err-002] 인코딩, 디코딩 KEY를 셋팅중에 오류가 발생하였습니다.

If I understand it right server returns some encode/decode error.

Is this expected error?

Could you provide a bit more details about your environment?
Do you use Linux or Windows? Maybe I am missing some additional parameters?
What is in your LANG env variable?
Could you also copy the entire output from your terminal?

@sacru2red
Copy link
Author

sacru2red commented Oct 29, 2024

ref, server is broken. 500 is ok

@w666

you are right.

In the example I gave, the 500 error you received (“[Err-002] An error occurred while setting the encoding and decoding KEY.”) is the expected response. In the current situation, you can just leave it at 200 OK.

I am in windows

@w666
Copy link
Collaborator

w666 commented Oct 29, 2024

@sacru2red

Sorry, I was not clear enough. I understand that server is broken, I just can't replicate the problem. Just tried on Windows, same result as on Linux regardless of whether I set forever: true, or not.

Would it be possible to provide full console output, like from my terminal below?

image

@sacru2red
Copy link
Author

@w666

Oops, I made a mistake too.

  • If you run the code provided above, it will work normally. in other words
    ERROR: soapenv:Receiver: undefined: [Err-002] An error occurred while setting the encoding and decoding KEY. is displayed.

  • If you update the code as below (if you create a client with default values ​​without a second parameter), an error will occur. (That is, “ERROR: socket hang up” is output.)

/**
const soapClient = await createClientAsync(${address}?wsdl, {
//it works if toggle under
// ref, server is broken. 500 is ok
httpClient,
})
*/
const soapClient = await createClientAsync(${address}?wsdl);

@sacru2red
Copy link
Author

I checked windows, ubuntu both

image

@w666
Copy link
Collaborator

w666 commented Oct 29, 2024

Okay, finally replicated the issue, but don't understand why null fixes that. I tried to pass http client with all the same headers as soap client set when using internal client, but it does not fail that way.

I will need to investigate that.

Copy link
Collaborator

@w666 w666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a test for this?
Or if I have time, I can have a look too.

src/http.ts Outdated Show resolved Hide resolved
@w666
Copy link
Collaborator

w666 commented Oct 30, 2024

@sacru2red could you please check if this PR fixes the problem?

@sacru2red
Copy link
Author

I thought about writing a test file before submitting this PR, but it was difficult to write.

I understand how this repo works (no issue capter), but it seems a bit difficult to contribute.

CONTRIBUTING.md << It is not detailed and is old, so it is not helpful.

Anyway, thank you for writing the test file and I will check it out.

@w666
Copy link
Collaborator

w666 commented Oct 30, 2024

Ah, yeah, project is very old, and I joined just recently, but I improved some areas already. I will have a look on docs when I have time.

@sacru2red
Copy link
Author

sacru2red commented Oct 31, 2024

@w666
It doesn't solve my problem.
Looking again, even my first commit doesn't solve my problem.

I will write the test code and code again and then tag it.
(I'm a beginner at Git and I'm not good at things like revert, so it might take a long time.)

memo: fix logic createClient, modify HttpClient.constructor.
why first http request (GET wsdl) can be set 'keep-alive'

@w666
Copy link
Collaborator

w666 commented Oct 31, 2024

@sacru2red, I think it should work.

No need to revert changes, I will squash all commits and update commit message when merge.

I attached small project I used for replicating the problem.
Jus unzip and install modules npm install then run it using npm run start, you will get the error you mentioned above.

image

Then update file node_modules/soap/lib/http.js like below

image

and run npm run start again, so you will get

image

I think that is what you expect, right?

soap-connection-header-test.zip

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

Successfully merging this pull request may close these issues.

2 participants