Getting an timeout when trying to send amount more than setReceiveMax

Hello @emschwartz, I did a quick run on this example.js provided in GitHub. I am getting a timeout error

Error: Timed out before the desired amount was sent (target: 10001, totalSent: 10000)
at Timeout.setTimeout (/Users/dornala/IdeaProjects/ilp-angular/node_modules/ilp-protocol-stream/src/stream.ts:283:16)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)

when trying to send amount higher than setReceiveMax and also client isn’t closing the connection.

Should we handle this manually?

Hi @adornala, good find. That case isn’t handled well now, although it’s unfortunately a bit tricky to determine what the best behavior to implement is.

Since the sender’s sendMax and receiver’s receiveMax are denoted in different currencies, they cannot be compared directly.

If the sender determines the exchange rate, they could use that to try to figure out if their sendMax falls within the receiver’s limits and possibly fail faster knowing that it is impossible to send the full amount. However, both the exchange rate and the receiver’s receiveMax can change while the sender is sending and could make possible to send the full amount.

Alternatively, the sender could notice the specific case where they can’t send any more because they have already hit (or come very close to) the receiveMax and throw a specific error so you don’t need to wait for the timeout. However, this doesn’t help the main issue that you still haven’t been able to deliver the full amount that you wanted to send. Also, there are cases where you may want the sendMax to be higher than the receiveMax so that the receiver can pull money as needed, potentially as a streaming service is being rendered, so it’s a bit unclear whether not being able to send the full sendMax is an error in all cases.

Thank you @emschwartz. Ya it makes sense.

Is it possible to transfer money bi-directionally? I tried sending money from server to client but I can’t make it to work, maybe I am doing something wrong. Let’s say If money can travel bidirectional (server <=> client), why can’t server take complete amount, pick max they allow and send remaining back to user(I expect money exchange multiple times)? A settlement should be done at some point anyways right!

Have you set the receiveMax on the client? It is set to 0 by default so it doesn’t accept incoming money (even returned funds) unless the user has explicitly allowed that.

(Assuming receiveMax is set high enough or that isn’t the issue) Is it possible that it sends the first 10000 units, then the last packet is sent for source amount 1, which the connector is rounding down to 0?

Getting timeout.

  // Handle incoming money
  stream.on('money', (amount: number) => {
    console.log(`Incoming payment: ${} , ${amount}`);
    if ( amount > 9900) {
      stream.sendTotal(100).then(() => {
        console.log(`Outgoing payment: ${} , 100`);
      }).catch((err) => console.log(err));

I couldn’t remove receiveMax, getting timeout if removed, so I added condition as above on server.

On Client, I did following:

const stream = clientConn.createStream();

I am getting following error at end:

Error: Stream was closed before the desired amount was sent (target: 100, totalSent: 0)
    at DataAndMoneyStream.endHandler (/Users/dornala/IdeaProjects/ilp-angular/node_modules/ilp-protocol-stream/src/stream.ts:273:18)
    at DataAndMoneyStream.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1103:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)

I also added wait on client side to receive credit sent by server(stream.receiveTotal(100)) sadly, It time’s out.

I will look into code and understand in deep @emschwartz. Thanks for help.:crossed_fingers: