# Getting an timeout when trying to send amount more than setReceiveMax

**URL:** <https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554>\
**Category:** General Questions\
**Created:** [April 29, 2019, 5:35pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554 "2019-04-29T17:35:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![adornala](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/adornala/32/269_2.png) [@adornala](https://forum.interledger.org/u/adornala)\
**Post date:** [April 29, 2019, 5:35pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554/1 "2019-04-29T17:35:49Z")

</div>

Hello @emschwartz, I did a quick run on [this](https://github.com/interledgerjs/ilp-protocol-stream/blob/master/example.js) 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?

---

<div class="post-metadata">

**Author:** ![emschwartz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/emschwartz/32/12_2.png) [@emschwartz](https://forum.interledger.org/u/emschwartz)\
**Post date:** [April 29, 2019, 5:57pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554/2 "2019-04-29T17:57:25Z")

</div>

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](https://forum.interledger.org/t/pull-payments/58) 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.

---

<div class="post-metadata">

**Author:** ![adornala](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/adornala/32/269_2.png) [@adornala](https://forum.interledger.org/u/adornala)\
**Post date:** [April 29, 2019, 6:13pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554/3 "2019-04-29T18:13:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![emschwartz](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/emschwartz/32/12_2.png) [@emschwartz](https://forum.interledger.org/u/emschwartz)\
**Post date:** [April 29, 2019, 6:23pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554/4 "2019-04-29T18:23:49Z")

</div>

Have you set the `receiveMax` on the client? It is set to 0 [by default](https://github.com/interledgerjs/ilp-protocol-stream/blob/master/src/stream.ts#L78) so it doesn’t accept incoming money (even returned funds) unless the user has explicitly allowed that.

---

<div class="post-metadata">

**Author:** ![kincaid](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/kincaid/32/39_2.png) [@kincaid](https://forum.interledger.org/u/kincaid)\
**Post date:** [April 29, 2019, 6:26pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554/5 "2019-04-29T18:26:22Z")

</div>

(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?

---

<div class="post-metadata">

**Author:** ![adornala](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.interledger.org/adornala/32/269_2.png) [@adornala](https://forum.interledger.org/u/adornala)\
**Post date:** [April 29, 2019, 7:22pm UTC](https://forum.interledger.org/t/getting-an-timeout-when-trying-to-send-amount-more-than-setreceivemax/554/6 "2019-04-29T19:22:29Z")

</div>

Getting timeout.

```
  // Handle incoming money
  stream.on('money', (amount: number) => {
    console.log(`Incoming payment: ${stream.id} , ${amount}`);
    if ( amount > 9900) {
      stream.sendTotal(100).then(() => {
        console.log(`Outgoing payment: ${stream.id} , 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();
stream.setReceiveMax(100);

```

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.🤞
