Change error message of web server continuations from "Sorry, this page has expired. Please go back."

30 views
Skip to first unread message

Marc Kaufmann

unread,
Dec 20, 2019, 8:45:43 AM12/20/19
to Racket Users
Hi all,

reading a past thread started by me, I realize that I should have learned how to implement Philip's advice on using stateless continuations, but well I didn't. So I still use vanilla `send/suspend/dispatch` and hence my users hit the "Sorry, this page has expired. Please go back." The quick fix is to tell them that they should go to page xyz.com. But I don't know how I can easily change this error message to add a link. Anyone?

I'm about to leave for travel or else I would have done some digging around.

Cheers,
Marc

PS: For some reason I keep hitting these errors faster than in the past - as in, within a few minutes. Any idea why that might be and how to increase the time? I can crank up the RAM of the machine too, anything that cuts down on developer time really. I'll be back in the new year to actually fix this, but not now.

George Neuner

unread,
Dec 20, 2019, 2:00:47 PM12/20/19
to Marc Kaufmann, racket users

On 12/20/2019 8:45 AM, Marc Kaufmann wrote:
> reading a past thread started by me, I realize that I should have
> learned how to implement Philip's advice on using stateless
> continuations, but well I didn't. So I still use vanilla
> `send/suspend/dispatch` and hence my users hit the "Sorry, this page
> has expired. Please go back." The quick fix is to tell them that they
> should go to page xyz.com. But I don't know how I can easily change
> this error message to add a link. Anyone?
>
> I'm about to leave for travel or else I would have done some digging
> around.
>
> PS: For some reason I keep hitting these errors faster than in the
> past - as in, within a few minutes. Any idea why that might be and how
> to increase the time? I can crank up the RAM of the machine too,
> anything that cuts down on developer time really. I'll be back in the
> new year to actually fix this, but not now.

Did you perhaps change the continuation manager - or its setup?
https://docs.racket-lang.org/web-server/servlet.html?q=ffi#%28part._managers%29

As to where to put your message: you can install a custom "expiration"
handler in the continuation manager.  Unfortunately I haven't done this
in a very long time, so I can't guide you through it.  Perhaps someone
(Jay?) knows exactly what to do.

George

Marc Kaufmann

unread,
Dec 21, 2019, 4:38:23 AM12/21/19
to Racket Users

Did you perhaps change the continuation manager - or its setup?
https://docs.racket-lang.org/web-server/servlet.html?q=ffi#%28part._managers%29


No, not really. I simply import send/suspend/dispatch etc and use them without doing anything in particular. I am requiring them within typed/racket if that matters via require/typed. So I have no idea where to configure the continuation manager - I don't even know where the current one is.

Cheers,
Marc

George Neuner

unread,
Dec 21, 2019, 4:31:43 PM12/21/19
to Marc Kaufmann, racket users

On 12/21/2019 4:38 AM, Marc Kaufmann wrote:

Did you perhaps change the continuation manager - or its setup?
https://docs.racket-lang.org/web-server/servlet.html?q=ffi#%28part._managers%29


No, not really. I simply import send/suspend/dispatch etc and use them without doing anything in particular. I am requiring them within typed/racket if that matters via require/typed. So I have no idea where to configure the continuation manager - I don't even know where the current one is.

If you started from serve/servlet - and didn't specify differently - then you are using the default LRU continuation manager.   If the load spikes, it will drop saved continuations to get memory use back under control.

You can specify to use a different manager (including a custom one) in the call to serve/servlet.


George

Philip McGrath

unread,
Dec 22, 2019, 3:59:02 PM12/22/19
to George Neuner, Marc Kaufmann, racket users
You can probably use `make-threshold-LRU-manager` with a much higher memory threshold than the default from `serve/servlet`, which is about 130 MB. The manager will start expiring continuations at that threshold even if you have lots of RAM available.

-Philip

--
You received this message because you are subscribed to the Google Groups "Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/f974666a-3e1a-3cd8-d371-09e9a283a157%40comcast.net.

Marc Kaufmann

unread,
Dec 23, 2019, 6:55:17 AM12/23/19
to Philip McGrath, George Neuner, racket users
In order to do everything as I do now - where I have been blissfully unaware of the managers - I do

```
(define the-manager-with-threshold (make-threshold-LRU-manager what-is-this-instance-expiration-handler? (* 512 1024 1024)))

(serve/servlet start ... <usual-stuff> ... #:manager the-manager-with-threshold)
```
and this would set the threshold to roughly 512 MB, rather than 130MB? By the way, where does it say that the default is 130MB?

Can I set the instance-expiration-manager to #f and that is the place where it generates the 'Sorry, this page link has expired' error? So I could provide a more meaningful error message there? Or better not, since it does more work behind the scenes?

Cheers,
Marc

George Neuner

unread,
Dec 23, 2019, 7:24:08 AM12/23/19
to Marc Kaufmann, racket users

On 12/23/2019 6:54 AM, Marc Kaufmann wrote:
> By the way, where does it say that the default is 130MB?

In the docs for serve/servlet.

> Can I set the instance-expiration-manager to #f and that is the place
> where it generates the 'Sorry, this page link has expired' error? So I
> could provide a more meaningful error message there? Or better not,
> since it does more work behind the scenes?

I don't know if you can set the handler to #f.  But you can replace it.

George

Marc Kaufmann

unread,
Dec 23, 2019, 7:57:03 AM12/23/19
to George Neuner, racket users
Of course. I read this line of the docs:

#:manager manager

but not this one:

manager : manager?
   = (make-threshold-LRU-manager #f (* 128 1024 1024))


which comes a page later given how many arguments serve/servlet has. I still haven't internalized how to read the documentation properly. Seems to suggest the default handler is #f, so that should be OK to do.

It also means that it didn't help much that I increased the current RAM on my server. Good to know.

Sam Tobin-Hochstadt

unread,
Dec 23, 2019, 9:28:13 AM12/23/19
to Marc Kaufmann, Philip McGrath, George Neuner, racket users
The default is documented here:
https://docs.racket-lang.org/web-server/run.html?q=serve%2Fservlet#%28def._%28%28lib._web-server%2Fservlet-env..rkt%29._serve%2Fservlet%29%29
as the default value for the `#:manager` argument.

The default handler is `#f`, which produces the behavior you see. You
can provide a different `request? -> response?` function instead.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/CAD7_NO7G%3DY_Q48_pfTYknpPCrfULRL3-yoCzqMVH0at372P0Uw%40mail.gmail.com.

Marc Kaufmann

unread,
Dec 23, 2019, 9:51:11 AM12/23/19
to Sam Tobin-Hochstadt, Philip McGrath, George Neuner, racket users
Yeah, I realized that after George's message.

I also now searched the Github for the message and found this:

```
#:manager
[manager
(make-threshold-LRU-manager
(lambda (request)
(response/xexpr
`(html (head (title "Page Has Expired."))
(body (p "Sorry, this page has expired. Please go back.")))))
(* 128 1024 1024))]
```

It seems this calls the serve/servlet not with the argument #f, but with the error message I find. Presumably this serve/servlet gets called by default, since I changed nothing yet get that error message? At least I have finally figured out what I need configuring.


Thanks everybody, that was quite helpful.

Cheers,
Marc
Reply all
Reply to author
Forward
0 new messages