tools-deps

Discuss tools.deps.alpha, tools.build, and the clj/clojure command-line scripts! See also #depstar #clj-new
2021-06-04T15:11:56.084300Z

I am having the most bizarre issue on my machine. I am on a Mac with the clojure cli installed via homebrew. If I launch an app or repl from cli, all network calls fail immediately with a socket error “Operation Not Permitted” and “Connection Refused”. Doing the exact same thing using leiningen works fine. Everything else is exactly the same. I’m not able to connect to databases or make http requests. I have the same issue when launching a server from figwheel (both legacy and figwheel-main). Occasionally I can get it to work for a single connection usually after uninstalling and re-installing Clojure in homebrew. I suspect this could be due to security software as my company has forced a few new scanners on our computers lately, but I’m just wondering what could possibly be different about the calls being made when launching via cli vs lein. Here is the simplest example of what fails for me. The equivalent with a project.clj and using lein repl works just fine. Any ideas what could possibly be different?

alexmiller 2021-06-04T15:20:59.085300Z

well if you want to get clj out of the debugging, you could clj -Spath and then java -cp <that-path> clojure.main

alexmiller 2021-06-04T15:22:16.086300Z

I'd wonder about Java version, and whether you have granted that Java version access to do network things

alexmiller 2021-06-04T15:22:52.087300Z

it will pop up a prompt for that - possible that's getting buried somehow through clj. just guessing

2021-06-04T15:22:56.087400Z

well i have tried multiple java versions. currently on adoptopenjdk 1.8. and using same version whether cli or lein

borkdude 2021-06-04T15:25:39.087800Z

Perhaps you could also try -Srepro which ignores config in your user folder

alexmiller 2021-06-04T15:27:29.088400Z

I'd rather get clj completely out of the way first and see if it still fails

2021-06-04T15:28:07.088900Z

so yes it does work when doing the java -cp and still fails when doing the -Srepro

alexmiller 2021-06-04T15:28:45.089100Z

does clj / clojure differ?

2021-06-04T15:32:22.089400Z

they both fail

alexmiller 2021-06-04T15:33:38.090100Z

the clojure bash script ultimately basically does java -cp cp clojure.main

alexmiller 2021-06-04T15:34:32.090500Z

what if you just wrap the call to java in a simple bash script?

2021-06-04T15:35:13.090700Z

i’ll give it a try

alexmiller 2021-06-04T15:36:02.091200Z

#!/usr/bin/env bash

exec java -cp ... clojure.main

2021-06-04T15:37:41.091500Z

hmm. that fails. seems surprising

alexmiller 2021-06-04T15:37:50.091700Z

the plot thickens :)

alexmiller 2021-06-04T15:37:59.091900Z

bash?

alexmiller 2021-06-04T15:38:28.092300Z

lein is also bash that is

alexmiller 2021-06-04T15:39:47.093100Z

maybe look at perms for the clojure and lein scripts and their ownership / group?

2021-06-04T15:40:24.093800Z

ok. so yeah tried each method a few times and consistently calling java -cp … directly works and running the bash script with the same thing doesn’t

alexmiller 2021-06-04T15:41:01.094100Z

what if you remove the exec in the script?

alexmiller 2021-06-04T15:41:36.094700Z

that's a difference between lein script and clj script although seems hard to believe that's the difference

2021-06-04T15:42:26.094900Z

hmm. yes removing exec works

alexmiller 2021-06-04T15:43:47.095100Z

interesting

2021-06-04T15:44:48.095900Z

heh - i have some other words for it but yeah that one fits too 🙂

2021-06-04T15:44:50.096100Z

maybe bash is replaced by recent security tools update?

alexmiller 2021-06-04T15:45:12.096500Z

as we say at Nubank... fascinating

2021-06-04T15:45:45.097200Z

i am using zsh but have also tried running it via bash w/ same result. wouldn’t think that would make a difference. course i wouldn’t think exec and no exec would make a difference

2021-06-04T15:46:09.097500Z

bash is used by clj/clojure scripts

2021-06-04T15:46:54.098200Z

looks like i’m using bash from homebrew not the system bash

2021-06-04T15:47:33.098700Z

mac os X is no longer shipped with system bash )

2021-06-04T15:48:46.100500Z

ah. true. not sure if it helps at all but i’m on Catalina just upgraded last week from Mojave in an attempt to fix this issue

dpsutton 2021-06-04T15:49:13.101100Z

I don't mean to derail but i had a colleague that would get different jvms when using lein and clj. Quite subtle and due to homebrew bringing in jdk15 for lein. You mentioned you were using the same 1.8 jvm but how sure are you on this? How did you check it at runtime. (sorry if this is irrelevant but just something i saw recently)

2021-06-04T15:50:20.102100Z

yeah i’ve been wondering about that too. is it possible to get the jvm from repl? i do have JAVA_HOME set and the clojure script seems to use that if set rather than the openjdk installed by homebrew

alexmiller 2021-06-04T15:51:15.102900Z

clj -M -e '(System/getProperty "java.version")'

2021-06-04T15:51:39.103400Z

“1.8.0_292”

alexmiller 2021-06-04T15:51:54.103700Z

I don't think the java is relevant here

2021-06-04T15:51:55.103900Z

same as when i do java -version

alexmiller 2021-06-04T15:52:22.104400Z

smells to me like there is some kind of prohibition re fork

alexmiller 2021-06-04T15:53:12.105200Z

I can imagine something like that from a security pov

alexmiller 2021-06-04T15:53:22.105500Z

I don't know what it is or how to check for it

2021-06-04T15:53:50.106100Z

what’s really baffling to me is when it will work 1 time. yesterday i uninstalled clojure, did brew cleanup, brew doctor, re-installed and it worked for several attempts. but then by the end of the day, it stopped working

2021-06-04T15:55:16.107300Z

also when i do have a working repl or application instance, it seems to work endlessly until that is broken. so definitely seems to be some sort of permissions thing on when it starts

alexmiller 2021-06-04T16:09:00.108200Z

do higher ports work? ports < 1024 require root privileges to open I believe

2021-06-04T16:10:13.108900Z

network calls to higher ports?

ghadi 2021-06-04T16:10:42.109600Z

privilege for low ports is on listening sockets, not destinations

alexmiller 2021-06-04T16:10:54.109800Z

ah, nvm

2021-06-04T16:11:27.110200Z

does it work with curl when it become broken with clj?

ghadi 2021-06-04T16:11:37.110500Z

> I suspect this could be due to security software as my company has forced a few new scanners on our computers lately what's that about?

ghadi 2021-06-04T16:11:48.110800Z

(reading through scrollback)

borkdude 2021-06-04T16:12:01.111Z

it's always the virus scanners

2021-06-04T16:13:37.111700Z

have Carbon Black and Microsoft Defender. wouldn’t shock me if there is other than I haven’t noticed

borkdude 2021-06-04T16:13:49.112200Z

are you on windows?

2021-06-04T16:13:54.112400Z

but none of my co-workers are having this issue

2021-06-04T16:13:59.112700Z

no. mac Catalina

borkdude 2021-06-04T16:14:19.113200Z

I didn't know Microsoft had a virus scanner for mac

2021-06-04T16:14:20.113400Z

my company likes to install as much Microsoft as they can though lol

alexmiller 2021-06-04T16:15:12.113900Z

the works for a while and then stops seems like it would match that theory

2021-06-04T16:15:55.114900Z

works very briefly then stops. almost like the first attempt gets through but then it gets blocked. but what could possibly be different about these network requests?

ghadi 2021-06-04T16:15:59.115200Z

can always check the diagnostic logs for rejected connection attempts

2021-06-04T16:16:11.115700Z

will say they fail immediately. don’t think they are actually making it to the network

ghadi 2021-06-04T16:16:22.116Z

(AV tools, surveillance ware or macOS Console)

ghadi 2021-06-04T16:16:40.116500Z

from the description, it doesn't seem like any network activity is happening

alexmiller 2021-06-04T16:18:46.117600Z

exec is going to replace the process so I can imagine a virus scanner seeing a process, replaced with another process space, then making network calls, as a possible virus

ghadi 2021-06-04T16:19:27.118200Z

most solid hypothesis so far ^

alexmiller 2021-06-04T16:19:37.118400Z

lein doesn't do the exec and works

borkdude 2021-06-04T16:19:51.118700Z

so then clojure would work, but not clj?

alexmiller 2021-06-04T16:20:00.119Z

well they both exec at the end

borkdude 2021-06-04T16:20:03.119300Z

oh wait, clojure also does exec

alexmiller 2021-06-04T16:20:38.120300Z

presumably a virus scanner would have some way to see and make this ok

borkdude 2021-06-04T16:20:40.120400Z

Well, if that theory holds, then @dwhite44 could try https://github.com/borkdude/deps.clj and see if that works, since it doesn't exec

borkdude 2021-06-04T16:20:59.120800Z

(just to confirm the theory more)

borkdude 2021-06-04T16:21:49.121600Z

@dwhite44 you could try this binary: https://github.com/borkdude/deps.clj/releases/download/v0.0.15/deps.clj-0.0.15-macos-amd64.zip Instead of clojure you invoke deps. deps -Spath or whatever

2021-06-04T16:21:58.122Z

i can give it a try. i think the sh file that works w/ no exec and fails with it is pretty good proof

borkdude 2021-06-04T16:22:05.122200Z

But it could be that the virus scanner also marks this binary as a virus of course

2021-06-04T16:23:43.124Z

is anybody familiar with how figwheel works? assume it also creates a new process and is likely why that’s not working? ultimately, I can get around the clojure cli not working by using leiningen but I can’t really do what i need to do if I can’t get around the figwheel problem

borkdude 2021-06-04T16:23:48.124200Z

you could also try the uberjar if that is the case: https://github.com/borkdude/deps.clj/releases/download/v0.0.15/deps.clj-0.0.15-standalone.jar

java -jar &lt;uberjar&gt;.jar -Spath

borkdude 2021-06-04T16:24:15.124400Z

let's take it one step at a time

2021-06-04T16:24:43.125Z

right. just wanted to add the fighwheel as an additional hint. seems like that probably confirms the issue is the extra process created by exec

2021-06-04T16:25:04.125400Z

well maybe not confirms but more evidence

2021-06-04T16:30:01.126200Z

yes it does work using borkdude/deps

alexmiller 2021-06-04T16:30:46.126500Z

I mean, you can hack your clojure to remove the exec :)

2021-06-04T16:36:01.127200Z

yeah. i’ll give my project a try using that. i suspect though that figwheel will make it fail for the same reason

2021-06-04T16:37:30.128600Z

but at least knowing that difference is causing the problem gives me something to tell the IT people so they can look at the anti-virus software settings or something. I really appreciate everybody’s help on this!

borkdude 2021-06-04T17:25:13.129200Z

@dwhite44 @alexmiller possibly this also works as a workaround:

alias exec=''

borkdude 2021-06-04T17:27:10.129900Z

I would write a wrapper script called clojure2 / clj2 where I would apply this only locally and then invoke the normal tool (to not mess with other calls of exec in your system)

2021-06-04T17:32:18.130300Z

good idea!

alexmiller 2021-06-04T17:40:18.130600Z

that's a built-in - can you really subvert it like that?

borkdude 2021-06-04T17:40:54.130900Z

I tested it and it seems to work

borkdude 2021-06-04T17:41:08.131100Z

at least in zsh

alexmiller 2021-06-04T17:41:20.131300Z

seems terrible :)

alexmiller 2021-06-04T17:41:31.131500Z

that you can do that :)

borkdude 2021-06-04T17:41:48.131800Z

it's a bit like clojure in this respect, I like it :P

borkdude 2021-06-04T17:43:58.132200Z

hmm, forget it, it doesn't seem to work

borkdude 2021-06-04T17:53:58.132600Z

This seems to work: clojure2:

#!/usr/bin/env bash

exec() {
 echo "exec replacement"
 eval $@
}

source clojure $@

borkdude 2021-06-04T17:55:30.132800Z

(I don't give up)

2021-06-04T18:34:05.133400Z

hmm. using that script actually doesn’t work for me even though i do see the “exec replacement” being output

borkdude 2021-06-04T18:43:51.134200Z

@dwhite44 to be 100% certain it's exec triggering your error, make a copy of clojure and remove "exec" from it

borkdude 2021-06-04T18:44:09.134600Z

if the error persists, bisect the script

borkdude 2021-06-04T18:45:17.135200Z

or maybe even easier: change echo "exec replacement" into echo "exec replacement" $@

borkdude 2021-06-04T18:45:33.135600Z

perhaps that will tell you something, not sure

borkdude 2021-06-04T18:48:26.136300Z

just copying the script and playing around with, inserting echo bla etc will probably help you most to discover what triggers it

2021-06-04T18:53:53.137Z

copying the original script and removing the execs does work

borkdude 2021-06-04T18:54:14.137200Z

ok, well, maybe keep doing that then :)

2021-06-04T18:57:59.138100Z

hmm. so interesting. even running the application with figwheel seems to be working using that. unless it’s just the brief temporary reprieve i sometimes get from making a change. guess i’ll know soon enough

2021-06-04T19:50:09.138700Z

this definitely seems to be at least a good solution for now. thanks everybody!