Skip to content
This repository has been archived by the owner on Nov 8, 2021. It is now read-only.

Invoice Create: HTTP/2 stream 0 was not closed cleanly #27

Open
jwes-dev opened this issue Mar 4, 2020 · 42 comments
Open

Invoice Create: HTTP/2 stream 0 was not closed cleanly #27

jwes-dev opened this issue Mar 4, 2020 · 42 comments

Comments

@jwes-dev
Copy link

jwes-dev commented Mar 4, 2020

Works with pairing, get token, etc. But create invoice request fails

I get the below error
Uncaught BTCPayServer\Client\ConnectionException: HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR

I sent out quick consecutive requests where the error said invalid currency. After like 3-4 such requests I started getting this error

@NicolasDorier
Copy link
Member

hey sorry I took much time to reply. Do you have any error in BTCPay Server logs? @woutersamaey you already saw that?

@jwes-dev
Copy link
Author

No worries.
Here is the error message from my logs
HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2) | btcpay/Client/Adapter/CurlAdapter.php | 77 | #0 btcpay/Client/Client.php(595): BTCPayServer\Client\Adapter\CurlAdapter->sendRequest(Object(BTCPayServer\Client\Request))
#1 btcpay/Client/Client.php(185): BTCPayServer\Client\Client->sendRequest(Object(BTCPayServer\Client\Request))
#2 Gateways/BTCPay.php(69): BTCPayServer\Client\Client->createInvoice(Object(BTCPayServer\Invoice))

@jwes-dev
Copy link
Author

This is the only log on I have on my end.
I still get this error. So if you want me to try something else to get more logs, let me know what to do

@woutersamaey
Copy link
Collaborator

@NicolasDorier unfortunately no, I am unfamiliar with this issue.

@NicolasDorier
Copy link
Member

@jwes-dev can you try to update curl? maybe you are using an old version of curl?

@jwes-dev
Copy link
Author

Tried that too.

I did find that when I changed my php version from 7.3 to 7.2 it started working until I again sent out couple of invalid requests.

@jwes-dev
Copy link
Author

curl update didn't work.

Could this be a security mechanism on BTCPay api against DDOS attacks?

@NicolasDorier
Copy link
Member

@jwes-dev no, ywe have an anti ddos protection, but you would get a proper HTTP code message...
Can you try to create an invoice via CURL? To facilitate, you can create a "legacy API Key" to authenticate via Basic authentication. I guess something is wrong with curl rather than the php library.

@jwes-dev
Copy link
Author

curl returns false

Thought this might help
curl_getinfo returned this
["size_download"]=> float(267)
["download_content_length"]=> float(-1)

@NicolasDorier
Copy link
Member

@jwes-dev no error on btcpayserver side logs? can you give me your curl request here so I can try?

@jwes-dev
Copy link
Author

How do i get btcpayserver side logs?

Do you want curl with url to my instance?

The curl works perfectly with https://testnet.demo.btcpayserver.org/
It has this issue only with my instance to a livenet and only after I sent out some requests with corrupt data

@jwes-dev
Copy link
Author

$Headers = [
'content-type: application/json',
'x-accept-version: 2.0.0',
'Authorization: Basic T3ZSMHZNbDBDUmI3MVVvbDc3MXZRSUk3MUcxb25oQlc3RXlCN25oWTBNRA==',
];

$Data = [
'price' => 500,
'currency' => 'USD',
'token' => 'OvR0vMl0CRb71Uol771vQII71G1onhBW7EyB7nhY0MD',
];

$ch = \curl_init();
\curl_setopt($ch, CURLOPT_URL, 'https://testnet.demo.btcpayserver.org/invoices');
\curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

if ($Headers !== null) {
\curl_setopt($ch, CURLOPT_HTTPHEADER, $Headers);
}

$postData = json_encode($Data);
\curl_setopt($ch, CURLOPT_POST, 1);
\curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

$output = \curl_exec($ch);
\curl_close($ch);
var_dump($output);

@NicolasDorier
Copy link
Member

one moment I check.

@NicolasDorier
Copy link
Member

same request with postman is working, checking with curl.

@NicolasDorier
Copy link
Member

NicolasDorier commented Mar 13, 2020

can you run this via command line:

curl -i  -H "Content-Type: application/json" -H "Authorization: Basic T3ZSMHZNbDBDUmI3MVVvbDc3MXZRSUk3MUcxb25oQlc3RXlCN25oWTBNRA==" -X "POST" --data "{}" https://testnet.demo.btcpayserver.org/invoices

It works for me.

curl --version
curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Release-Date: 2018-01-24
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL

@jwes-dev
Copy link
Author

let me check

@NicolasDorier
Copy link
Member

If it still does not work, try adding the --http1.1 and let me know if that's better.

@jwes-dev
Copy link
Author

ok it's working when I request from my local
but fails on server

However
when i ran curl from command line it still gave me the error but i also got the response

curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)
{"error":"Warning: No wallet has been linked to your BTCPay Store. See the following link for more information on how to connect your store and wallet. (https://docs.btcpayserver.org/getting-started/connectwallet)\n3/13/20 7:20:50 AM: Creation of invoice starting\n"}

@NicolasDorier
Copy link
Member

NicolasDorier commented Mar 13, 2020

curl -i  -H "Content-Type: application/json" -H "Authorization: Basic T3ZSMHZNbDBDUmI3MVVvbDc3MXZRSUk3MUcxb25oQlc3RXlCN25oWTBNRA==" -X "POST" --data '{ "price" : 500, "currency": "USD" }' https://testnet.demo.btcpayserver.org/invoices
HTTP/2 200
server: nginx
date: Fri, 13 Mar 2020 07:27:04 GMT
content-type: application/json; charset=utf-8
content-length: 2056
access-control-allow-origin: *
referrer-policy: same-origin
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: DENY
strict-transport-security: max-age=31536000

{"facade":"pos/invoice","data":{"url":"https://testnet.demo.btcpayserver.org/invoice?id=XBxxTtTNVqA69wqCYd1tJ2","posData":null,"status":"new","btcPrice":"0.09669123","btcDue":"0.09669123","cryptoInfo":[{"cryptoCode":"BTC","paymentType":"BTCLike","rate":5171.1,"exRates":{"USD":0.0},"paid":"0.00000000","price":"0.09669123","due":"0.09669123","paymentUrls":{"BIP21":"bitcoin:tb1qsauravw79a9ks7e9r6whed8r7q5dhr2fn95pzv?amount=0.09669123","BIP72":null,"BIP72b":null,"BIP73":null,"BOLT11":null},"address":"tb1qsauravw79a9ks7e9r6whed8r7q5dhr2fn95pzv","url":"https://testnet.demo.btcpayserver.org/i/BTC/XBxxTtTNVqA69wqCYd1tJ2","totalDue":"0.09669123","networkFee":"0.00000000","txCount":0,"cryptoPaid":"0.00000000","payments":[]}],"price":500.0,"currency":"USD","exRates":{"USD":0.0},"buyerTotalBtcAmount":null,"itemDesc":null,"itemCode":null,"orderId":null,"guid":"fb34180e-56a0-4a7c-9906-678fb8de8371","id":"XBxxTtTNVqA69wqCYd1tJ2","invoiceTime":1584084424000,"expirationTime":1584085324000,"currentTime":1584084424938,"lowFeeDetected":false,"btcPaid":"0.00000000","rate":5171.1,"exceptionStatus":false,"paymentUrls":{"BIP21":"bitcoin:tb1qsauravw79a9ks7e9r6whed8r7q5dhr2fn95pzv?amount=0.09669123","BIP72":null,"BIP72b":null,"BIP73":null,"BOLT11":null},"refundAddressRequestPending":false,"buyerPaidBtcMinerFee":null,"bitcoinAddress":"tb1qsauravw79a9ks7e9r6whed8r7q5dhr2fn95pzv","token":"QFZCHAEL7CSDFvmcoLZKnr","flags":{"refundable":false},"paymentSubtotals":{"BTC":9669123.0},"paymentTotals":{"BTC":9669123.0},"amountPaid":0,"minerFees":{"BTC":{"satoshisPerByte":1.0,"totalFee":0.0}},"exchangeRates":{"BTC":{"USD":0.0}},"supportedTransactionCurrencies":{"BTC":{"enabled":true,"reason":null}},"addresses":{"BTC":"tb1qsauravw79a9ks7e9r6whed8r7q5dhr2fn95pzv"},"paymentCodes":{"BTC":{"BIP21":"bitcoin:tb1qsauravw79a9ks7e9r6whed8r7q5dhr2fn95pzv?amount=0.09669123","BIP72":null,"BIP72b":null,"BIP73":null,"BOLT11":null}},"buyer":{"name":null,"address1":null,"address2":null,"locality":null,"region":null,"postalCode":null,"country":null,"phone":null,"email":null}}}

@NicolasDorier
Copy link
Member

I think something funky with the curl on the server. What version is it?

@jwes-dev
Copy link
Author

curl 7.64.0
It's a debian server

@NicolasDorier
Copy link
Member

dammit, when you copy my command above same issue?

@jwes-dev
Copy link
Author

just a sec let me check

@NicolasDorier
Copy link
Member

I tried this command on 3 different server and my local machine, all worked.

@jwes-dev
Copy link
Author

HTTP/2 400
server: nginx
date: Fri, 13 Mar 2020 07:33:04 GMT
content-type: application/json
access-control-allow-origin: *
referrer-policy: same-origin
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
x-frame-options: DENY
strict-transport-security: max-age=31536000

curl: (92) HTTP/2 stream 0 was not closed cleanly: INTERNAL_ERROR (err 2)
{"error":"Warning: No wallet has been linked to your BTCPay Store. See the following link for more information on how to connect your store and wallet. (https://docs.btcpayserver.org/getting-started/connectwallet)\n3/13/20 7:33:04 AM: Creation of invoice starting\n"}

@NicolasDorier
Copy link
Member

dammit and it happen only on this server? Can you copy paste the output of curl --version ?

@jwes-dev
Copy link
Author

yes just a sec

@jwes-dev
Copy link
Author

curl 7.64.0 (x86_64-pc-linux-gnu) libcurl/7.64.0 OpenSSL/1.1.1d zlib/1.2.11 libidn2/2.0.5 libpsl/0.20.2 (+libidn2/2.0.5) libssh2/1.8.0 nghttp2/1.36.0 librtmp/2.3
Release-Date: 2019-02-06
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP HTTP2 UnixSockets HTTPS-proxy PSL

@NicolasDorier
Copy link
Member

@jwes-dev I am sorry but I am at loss trying to know what is going on.
what if you add --http1.1 ?

@jwes-dev
Copy link
Author

let me check

@jwes-dev
Copy link
Author

Got this

curl: (18) transfer closed with outstanding read data remaining
{"error":"Warning: No wallet has been linked to your BTCPay Store. See the following link for more information on how to connect your store and wallet. (https://docs.btcpayserver.org/getting-started/connectwallet)\n3/13/20 7:41:54 AM: Creation of invoice starting\n"}

@NicolasDorier
Copy link
Member

Sorry I don't know, is it possible a proxy is messing up the request?
Else try another version, mine is

curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets

@jwes-dev
Copy link
Author

might work. Let me try a different version

@jwes-dev
Copy link
Author

You said we can check btcpayserver logs. How do I get those logs?

@NicolasDorier
Copy link
Member

@jwes-dev you can't I can only get it. I checked, nothing wrong on my side.

@jwes-dev
Copy link
Author

Aren't btcpay logs stored on my server hosting the btcpayserver instance?

@NicolasDorier
Copy link
Member

@jwes-dev testnet.btcpayserver.org is my server, not yours.

@jwes-dev
Copy link
Author

Terribly sorry. Think there has been a misunderstanding.
Earlier I couldn't share the actual url
Here's the actual server I was pinging.

https://btcpay.maine-bitcoin.com

I have no issue with testnet.demo.btcpayserver.org. The issue was with the copy of btcpayserver I have.

Terribly sorry about the mixup

@jwes-dev
Copy link
Author

How do i get btcpayserver side logs?

Do you want curl with url to my instance?

The curl works perfectly with https://testnet.demo.btcpayserver.org/
It has this issue only with my instance to a livenet and only after I sent out some requests with corrupt data

Perhaps I should have posted this along with the issue as the opener :(. Again terribly sorry about the mixup. Could you help me?

@NicolasDorier
Copy link
Member

NicolasDorier commented Mar 16, 2020

@jwes-dev can you give me a curl request against your server I can test on my side?
What kind of deploymet you have ? Docker/Lunanode?

@jwes-dev
Copy link
Author

curl --location --request POST 'https://btcpay.maine-bitcoin.com/invoices'
--header 'Content-Type: application/json'
--header 'Authorization: Basic RWREV25yREhPWkQ3cGRvblA3SENyMGtab1dpSHJHYmtrWWl2N1l2TEJVRA=='
--data-raw '{"price":500,"currency":"USD","token":"OvR0vMl0CRb71Uol771vQII71G1onhBW7EyB7nhY0MD"}'

The problem was because I did not link a wallet. BUT it should have still returned a error message. In my case it was closing the connection

@NicolasDorier
Copy link
Member

NicolasDorier commented Mar 26, 2020

I tried on your node:

curl --location --request POST 'https://btcpay.maine-bitcoin.com/invoices' --header 'Content-Type: application/json' --header 'Authorization: Basic RWREV25yREhPWkQ3cGRvblA3SENyMGtab1dpSHJHYmtrWWl2N1l2TEJVRA==' --data-raw '{"price":500,"currency":"USD","token":"OvR0vMl0CRb71Uol771vQII71G1onhBW7EyB7nhY0MD"}'
curl: (92) HTTP/2 stream 1 was not closed cleanly: INTERNAL_ERROR (err 2)
{"error":"Warning: No wallet has been linked to your BTCPay Store. See the following link for more information on how to connect your store and wallet. (https://docs.btcpayserver.org/getting-started/connectwallet)\n3/26/20 8:47:28 AM: Creation of invoice starting\n3/26/20 8:47:28 AM: BTC_USD: The rating rule is coinaverage(BTC_USD)\n3/26/20 8:47:28 AM: BTC_USD: The evaluated rating rule is ERR_RATE_UNAVAILABLE(coinaverage, BTC_USD)\n3/26/20 8:47:28 AM: BTC_USD: Rate rule error (RateUnavailable)\n3/26/20 8:47:28 AM: BTC_USD: Exception reaching exchange coinaverage (Unauthorized access to the API, premium plan needed)\n"}

Sorry I don't really know why you don't have this error and instead connection get cut.
btw, you should update your btcpayserver instance, we don't use coinaverage anymore.

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

No branches or pull requests

3 participants