babashka-sci-dev

Crispin 2022-09-01T06:25:01.414209Z

I'm thinking about what it would take to add return values to pod async callbacks...

Crispin 2022-09-06T03:41:55.575739Z

Have ended up encountering more issues here.

Crispin 2022-09-06T03:42:20.326589Z

The inability to call any pod function from within a pod "method"

Crispin 2022-09-06T03:42:31.342799Z

hangs bb in a deadlock

Crispin 2022-09-06T03:42:46.844629Z

Im in the middle of invstigations...

Crispin 2022-09-06T03:56:51.680339Z

oh, sorted it. My future for the callback had to encompass the method apply aswell... just moved my future a little further up...

borkdude 2022-09-01T14:16:45.060319Z

Hey, now looking at this message.

borkdude 2022-09-01T14:22:09.223159Z

Can you describe the problem to me in terms of examples / requirements instead of proposed code changes?

borkdude 2022-09-01T14:22:55.498729Z

Is it related to https://github.com/babashka/pods#async?

Crispin 2022-09-01T14:23:23.419019Z

hey! yeah. its the pod async callback

Crispin 2022-09-01T14:24:21.366439Z

It would be awesome to make it possible for your callback to return a value, and that value could be sent to the pod, and used there

borkdude 2022-09-01T14:24:28.617049Z

it's a while ago since I looked at it so maybe you can explain the idea to me in more general terms 😅

Crispin 2022-09-01T14:26:00.739299Z

I have this bbssh pod underway. And in the pod I need to make a UserInfo class instance. And this is used by JSch to do things like, get the users password. Or ask for a passphrase for a key decryption. or some other things.

Crispin 2022-09-01T14:27:35.471189Z

so when JSch calls a method on this class, like getPassword, I could fire an async callback in the bb code... maybe it would return a string. Or maybe it would prompt at the terminal. Or maybe it would open a window with a text prompt. The end user could determine that

Crispin 2022-09-01T14:27:54.755059Z

but when that callback returns a value, it is just dropped

Crispin 2022-09-01T14:28:40.954189Z

Its not a complete blocker, but if it were possible it would lead to a really elegant bbssh api

Crispin 2022-09-01T14:29:08.673229Z

and if it is implemented, you could do even more with a pod

Crispin 2022-09-01T14:29:22.334849Z

it would be pretty rarely used, but very useful to have

borkdude 2022-09-01T14:31:11.409179Z

To recap for myself: In the case of the async watch function, what happens: The client calls watch, which is implemented as a client side function that calls the low level async pod api, which allows you to register a callback that gets called on 1 or more async replies (or an error handler). Those replies get sent back to the client. This is basically the same as a synchronous function call: client asks, pod sends back.

borkdude 2022-09-01T14:31:27.532579Z

And now are asking beyond this, what exactly?

Crispin 2022-09-01T14:31:27.577829Z

as it's not there I have to hard code the behavior here into the pod. This is the old spire UserInfo part: https://github.com/epiccastle/spire/blob/master/src/clj/spire/ssh.clj#L48-L60

Crispin 2022-09-01T14:32:04.332629Z

so what Im asking is, you register the callback

Crispin 2022-09-01T14:33:11.378879Z

that gets called one or more async replies (or an error handler). Those replies get sent back to the client as arguments on a :success, or a :error callback

borkdude 2022-09-01T14:33:27.220439Z

yes. this already exists.. right?

Crispin 2022-09-01T14:33:39.975129Z

and then... the return value of those callbacks is then send back to the pod along with the id

Crispin 2022-09-01T14:34:08.371729Z

(this could be configurable somehow... or only if its not nil. Details could be worked out)

borkdude 2022-09-01T14:34:19.724179Z

why - the pod sent those values to the client, why do you want to send them from the client to the pod?

Crispin 2022-09-01T14:34:51.166219Z

because the client has now used those values to go and do something and return an answer that the pod needs

Crispin 2022-09-01T14:35:02.158109Z

hmmmm...

Crispin 2022-09-01T14:35:07.631769Z

or I could invoke again?

borkdude 2022-09-01T14:35:12.731009Z

shouldn't the client just call another pod function then?

Crispin 2022-09-01T14:35:40.741869Z

yes. that seems obvious... 🤔

Crispin 2022-09-01T14:36:04.600109Z

thats basically what the response is going to do anyway

Crispin 2022-09-01T14:36:26.418829Z

yep thats a good idea. a continuations style. call on with the answer

➕ 1
Crispin 2022-09-01T14:37:19.686749Z

thanks! I don't know why I didn't think of that

Crispin 2022-09-01T14:37:25.578339Z

too down in the weeds

borkdude 2022-09-01T14:37:33.855829Z

happy to help :)

Crispin 2022-09-01T14:37:45.656479Z

While I have you, one other thing I notice...

Crispin 2022-09-01T14:38:07.244389Z

Is there an issue with async callback with {:transport :socket}

Crispin 2022-09-01T14:38:21.036749Z

When I call it I get No matching clause

borkdude 2022-09-01T14:38:30.071039Z

hmmm

borkdude 2022-09-01T14:38:34.603579Z

don't know...

borkdude 2022-09-01T14:38:39.990819Z

could be!

Crispin 2022-09-01T14:38:49.134809Z

I'll just point at the code... 1 sec

Crispin 2022-09-01T14:40:04.314919Z

and then it fails on the subsequent case for the encoding

borkdude 2022-09-01T14:40:23.992949Z

and what is the encoding?

borkdude 2022-09-01T14:40:44.268339Z

format you mean, right?

Crispin 2022-09-01T14:41:34.854009Z

yes format

borkdude 2022-09-01T14:41:54.920299Z

maybe you could insert some debugging

Crispin 2022-09-01T14:41:57.635629Z

Im not sure why its nil. I just started digging into this

borkdude 2022-09-01T14:42:03.897839Z

thanks

Crispin 2022-09-01T14:42:05.574249Z

just checking its not something you know about?

borkdude 2022-09-01T14:42:10.766349Z

doesn't ring a bell

Crispin 2022-09-01T14:42:20.215999Z

ok cool. I'll find out whats going on

Crispin 2022-09-01T14:42:44.100019Z

thanks again for the clarity

🙏 1
Crispin 2022-09-01T15:06:08.527999Z

OK. Its not a bug.

Crispin 2022-09-01T15:06:32.497059Z

its even in the docs, but maybe it's not as clear as it could be

Crispin 2022-09-01T15:07:24.643439Z

https://github.com/babashka/pods#async The arguments to babashka.pods/invoke are: a pod identifier string derived from the first described namespace.

Crispin 2022-09-01T15:09:20.017419Z

Maybe a better error when you get that wrong would be good?

Crispin 2022-09-01T15:12:25.876249Z

I could add that if you would accept it

borkdude 2022-09-01T15:13:30.803199Z

Sounds good, if there's not much of a performance impact

👍 1
Crispin 2022-09-01T15:14:01.986739Z

https://github.com/babashka/pods/blob/master/src/babashka/pods/impl.clj#L448 be just here. If this returns nil it raises an exception

Crispin 2022-09-01T15:15:00.975329Z

bedtime for me. I'll continue this tomorrow. Thanks for your help

👍 1
borkdude 2022-09-01T15:16:18.250329Z

seems good, sleep well!

Crispin 2022-09-01T06:26:41.853069Z

and encoding it and sending it back to the pod. with an id. and maybe into the pod with a new bencode command like retval

Crispin 2022-09-01T06:28:20.757599Z

it would be up to the pod to get it to where it needs to go, with a promise or something.

Crispin 2022-09-01T06:29:56.264259Z

would we make a new id and send with the invoke (this is your retval id, use it to deliver the return value)? Or could we use the existing invoke id?

Crispin 2022-09-01T06:30:43.758819Z

What are your feelings on this kind of addition @borkdude? Assuming it could be done, is it something you would consider merging?

Crispin 2022-09-02T07:47:42.996329Z

ok. amazingly I got this round trip pod->client->pod working! 🎉

Crispin 2022-09-02T07:47:55.595879Z

its a bit of a dead-lock trap for the unwary

Crispin 2022-09-02T07:49:59.660539Z

in particular I had to call the client->pod "return the result" call inside a future to prevent a deadlock in bb. For the brave and true who follow along in the future: https://github.com/epiccastle/bbssh/blob/0958baa17c42cb0b22f73852dcbd05a5639015dc/src/bb/pod/epiccastle/bbssh/user_info.clj#L27

Crispin 2022-09-02T07:51:05.417499Z

I also had to improve my own pod mainloop code. I had some similar issues in it.

Crispin 2022-09-02T07:52:09.939769Z

it's quite amazing to see. so this code: https://github.com/epiccastle/bbssh/blob/0958baa17c42cb0b22f73852dcbd05a5639015dc/test/bb.clj#L34-L61

Crispin 2022-09-02T07:52:31.643499Z

defined all the "methods" on the object (that lives over in the pod)

Crispin 2022-09-02T07:53:08.355849Z

and they will be called in your bb code as they are called over in the pod, and your return values will be returned

Crispin 2022-09-02T07:53:13.531909Z

pretty cool stuff

borkdude 2022-09-02T18:13:54.846959Z

good to hear!