0

I have created a simple function, which is basically almost identical to the one in the stellar documentation "Sending and receiving custom assets" found here

I constantly get error 504 timeouts ... it's basically timing out every single time I try it.

Note - the secret keys referred to in the function declaration relate to funded accounts on the stellar testnet.

My function differs from the stellar one as follows: - it has "fee:200" and "fee:500" in the .TransactionBuilder calls [as now recommended by stellar I believe) (I experimented with values here, no difference found, still get 504 timeout).

function TryStellarEntireScenario ( SK_Issuer , SK_Distributor ,SK_userSender  ,SK_userReceiver ) {
// the SK's are the Secret keys  

var server = new StellarSdk.Server('https://horizon-testnet.stellar.org');
StellarSdk.Network.useTestNetwork();
// The other set-ups from the server are done further up this source code file

// Keys for accounts to issue and receive the new asset

var issuingKeys = StellarSdk.Keypair
.fromSecret(SK_Issuer);
var receivingKeys = StellarSdk.Keypair
.fromSecret(SK_Distributor);


// Create an object to represent the new asset
var astroDollar = new StellarSdk.Asset('AstroDollar', issuingKeys.publicKey());

// First, the receiving account must trust the asset
server.loadAccount(receivingKeys.publicKey())
.then(function(receiver) {
 var transaction = new StellarSdk.TransactionBuilder(receiver, {fee:200})
   // The `changeTrust` operation creates (or alters) a trustline
   // The `limit` parameter below is optional
   .addOperation(StellarSdk.Operation.changeTrust({
     asset: astroDollar,
     limit: '1000'
   }))
   // setTimeout is required for a transaction
   .setTimeout(100)
   .build();
 transaction.sign(receivingKeys);
 return server.submitTransaction(transaction);
})

// Second, the issuing account actually sends a payment using the asset
.then(function() {
 return server.loadAccount(issuingKeys.publicKey())
})
.then(function(issuer) {
 var transaction = new StellarSdk.TransactionBuilder(issuer, {fee:500})
   .addOperation(StellarSdk.Operation.payment({
     destination: receivingKeys.publicKey(),
     asset: astroDollar,
     amount: '10'
   }))
   // setTimeout is required for a transaction
   .setTimeout(100)
   .build();
 transaction.sign(issuingKeys);
 return server.submitTransaction(transaction);
})
.catch(function(error) {
 console.error('Error!', error);
});

}

Here is the error log:

Error! { Error: Request failed with status code 504
    at createError (C:\Users\mhard\MH_DB_Dev\SimpleExample\node_modules\axios\lib\core\createError.js:16:15)
    at settle (C:\Users\mhard\MH_DB_Dev\SimpleExample\node_modules\axios\lib\core\settle.js:18:12)
    at IncomingMessage.handleStreamEnd (C:\Users\mhard\MH_DB_Dev\SimpleExample\node_modules\axios\lib\adapters\http.js:201:11)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  config:
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 60000,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
     headers:
      { Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/x-www-form-urlencoded',
        'X-Client-Name': 'js-stellar-sdk',
        'X-Client-Version': '0.15.3',
        'User-Agent': 'axios/0.18.0',
        'Content-Length': 311 },
     method: 'post',
     url: 'https://horizon-testnet.stellar.org/transactions',
     data: 'tx=AAAAAO6dqZWvM8smCFbXvnceXkb4OfCRjVxF1BwPz9hkEHlfAAAAyAADiukAAAABAAAAAQAAAAAAAAAAAAAAAF1VFzMAAAAAAAAAAQAAAAAAAAAGAAAAAkFzdHJvRG9sbGFyAAAAAADCpKTKB1QZ83KqY5yS1pJuBj%2FkizTq9IfSurr4axwabAAAAAJUC%2BQAAAAAAAAAAAFkEHlfAAAAQHGAvUrL7Lj1veTs2YEAV3ZkccixLYdl6Z3ZIJveuk2x32YWqhHOk3BCIcY8m4MpdO8nuHF%2BysVHwhD8P8jGLAQ%3D' },
  request:
   ClientRequest {
     domain: null,
     _events:
      { socket: [Function],
        abort: [Function],
        aborted: [Function],
        error: [Function],
        timeout: [Function],
        prefinish: [Function: requestOnPrefinish] },
     _eventsCount: 6,
     _maxListeners: undefined,
     output: [],
     outputEncodings: [],
     outputCallbacks: [],
     outputSize: 0,
     writable: true,
     _last: true,
     upgrading: false,
     chunkedEncoding: false,
     shouldKeepAlive: false,
     useChunkedEncodingByDefault: true,
     sendDate: false,
     _removedConnection: false,
     _removedContLen: false,
     _removedTE: false,
     _contentLength: null,
     _hasBody: true,
     _trailer: '',
     finished: true,
     _headerSent: true,
     socket:
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'horizon-testnet.stellar.org',
        npnProtocol: undefined,
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 9,
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'horizon-testnet.stellar.org',
        _readableState: [Object],
        readable: false,
        domain: null,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 592,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: null,
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular],
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 58,
        [Symbol(bytesRead)]: 608 },
     connection:
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'horizon-testnet.stellar.org',
        npnProtocol: undefined,
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 9,
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'horizon-testnet.stellar.org',
        _readableState: [Object],
        readable: false,
        domain: null,
        _maxListeners: undefined,
        _writableState: [Object],
        writable: false,
        allowHalfOpen: false,
        _bytesDispatched: 592,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: null,
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular],
        _idleNext: null,
        _idlePrev: null,
        _idleTimeout: -1,
        [Symbol(asyncId)]: 58,
        [Symbol(bytesRead)]: 608 },
     _header: 'POST /transactions HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nX-Client-Name: js-stellar-sdk\r\nX-Client-Version: 0.15.3\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 311\r\nHost: horizon-testnet.stellar.org\r\nConnection: close\r\n\r\n',
     _onPendingData: [Function: noopPendingOutput],
     agent:
      Agent {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object],
        requests: {},
        sockets: [Object],
        freeSockets: {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        maxCachedSessions: 100,
        _sessionCache: [Object] },
     socketPath: undefined,
     timeout: undefined,
     method: 'POST',
     path: '/transactions',
     _ended: true,
     res:
      IncomingMessage {
        _readableState: [Object],
        readable: false,
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        socket: [Object],
        connection: [Object],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        headers: [Object],
        rawHeaders: [Array],
        trailers: {},
        rawTrailers: [],
        upgrade: false,
        url: '',
        method: null,
        statusCode: 504,
        statusMessage: 'Gateway Timeout',
        client: [Object],
        _consuming: true,
        _dumped: false,
        req: [Circular],
        responseUrl: 'https://horizon-testnet.stellar.org/transactions',
        redirects: [],
        read: [Function] },
     aborted: undefined,
     timeoutCb: null,
     upgradeOrConnect: false,
     parser: null,
     maxHeadersCount: null,
     _redirectable:
      Writable {
        _writableState: [Object],
        writable: true,
        domain: null,
        _events: [Object],
        _eventsCount: 2,
        _maxListeners: undefined,
        _options: [Object],
        _ended: true,
        _ending: true,
        _redirectCount: 0,
        _redirects: [],
        _requestBodyLength: 311,
        _requestBodyBuffers: [],
        _onNativeResponse: [Function],
        _currentRequest: [Circular],
        _currentUrl: 'https://horizon-testnet.stellar.org/transactions' },
     [Symbol(outHeadersKey)]:
      { accept: [Array],
        'content-type': [Array],
        'x-client-name': [Array],
        'x-client-version': [Array],
        'user-agent': [Array],
        'content-length': [Array],
        host: [Array] } },
  response:
   { status: 504,
     statusText: 'Gateway Timeout',
     headers:
      { 'cache-control': 'no-cache, no-store, max-age=0',
        'content-type': 'application/problem+json; charset=utf-8',
        date: 'Thu, 15 Aug 2019 08:25:20 GMT',
        vary: 'Origin',
        'x-ratelimit-limit': '101',
        'x-ratelimit-remaining': '100',
        'x-ratelimit-reset': '1',
        'content-length': '310',
        connection: 'Close' },
     config:
      { adapter: [Function: httpAdapter],
        transformRequest: [Object],
        transformResponse: [Object],
        timeout: 60000,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        validateStatus: [Function: validateStatus],
        headers: [Object],
        method: 'post',
        url: 'https://horizon-testnet.stellar.org/transactions',
        data: 'tx=AAAAAO6dqZWvM8smCFbXvnceXkb4OfCRjVxF1BwPz9hkEHlfAAAAyAADiukAAAABAAAAAQAAAAAAAAAAAAAAAF1VFzMAAAAAAAAAAQAAAAAAAAAGAAAAAkFzdHJvRG9sbGFyAAAAAADCpKTKB1QZ83KqY5yS1pJuBj%2FkizTq9IfSurr4axwabAAAAAJUC%2BQAAAAAAAAAAAFkEHlfAAAAQHGAvUrL7Lj1veTs2YEAV3ZkccixLYdl6Z3ZIJveuk2x32YWqhHOk3BCIcY8m4MpdO8nuHF%2BysVHwhD8P8jGLAQ%3D' },
     request:
      ClientRequest {
        domain: null,
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        socket: [Object],
        connection: [Object],
        _header: 'POST /transactions HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/x-www-form-urlencoded\r\nX-Client-Name: js-stellar-sdk\r\nX-Client-Version: 0.15.3\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 311\r\nHost: horizon-testnet.stellar.org\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Object],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/transactions',
        _ended: true,
        res: [Object],
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        _redirectable: [Object],
        [Symbol(outHeadersKey)]: [Object] },
     data:
      { type: 'https://stellar.org/horizon-errors/timeout',
        title: 'Timeout',
        status: 504,
        detail: 'Your request timed out before completing.  Please try your request again. If you are submitting a transaction make sure you are sending exactly the same transaction (with the same sequence number).' } } }

Thanks in anticipation, if anyone can help ?

1

1 Answer 1

2

Since the testnet is getting flooded with transactions I would recommend setting a longer time bound on your transaction to see if that helps - yours is currently set to 100 seconds.

There's some documentation on that here: https://stellar.github.io/js-stellar-sdk/TransactionBuilder.html

1
  • I set the timeouts to 1,000 seconds, and it made no difference. I also set the fees to 20,000, again no difference. Even with timeouts of 1000 seconds, the error (504) came up after 2 minutes each time (i.e. roughly 120 seconds). Any other thoughts ? Thanks - Mark
    – StellarFan
    Commented Aug 20, 2019 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.