Fork me on GitHub
#tools-deps
<
2021-06-04
>
dwhite4415:06:56

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?

Alex Miller (Clojure team)15:06:59

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

Alex Miller (Clojure team)15:06:16

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

Alex Miller (Clojure team)15:06:52

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

dwhite4415:06:56

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

borkdude15:06:39

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

Alex Miller (Clojure team)15:06:29

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

dwhite4415:06:07

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

Alex Miller (Clojure team)15:06:45

does clj / clojure differ?

dwhite4415:06:22

they both fail

Alex Miller (Clojure team)15:06:38

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

Alex Miller (Clojure team)15:06:32

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

dwhite4415:06:13

i’ll give it a try

Alex Miller (Clojure team)15:06:02

#!/usr/bin/env bash

exec java -cp ... clojure.main

dwhite4415:06:41

hmm. that fails. seems surprising

Alex Miller (Clojure team)15:06:28

lein is also bash that is

Alex Miller (Clojure team)15:06:47

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

dwhite4415:06:24

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

Alex Miller (Clojure team)15:06:01

what if you remove the exec in the script?

Alex Miller (Clojure team)15:06:36

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

dwhite4415:06:26

hmm. yes removing exec works

dwhite4415:06:48

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

delaguardo15:06:50

maybe bash is replaced by recent security tools update?

Alex Miller (Clojure team)15:06:12

as we say at Nubank... fascinating

dwhite4415:06:45

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

delaguardo15:06:09

bash is used by clj/clojure scripts

dwhite4415:06:54

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

delaguardo15:06:33

mac os X is no longer shipped with system bash )

dwhite4415:06:46

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

dpsutton15:06:13

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)

dwhite4415:06:20

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

Alex Miller (Clojure team)15:06:15

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

dwhite4415:06:39

“1.8.0_292”

Alex Miller (Clojure team)15:06:54

I don't think the java is relevant here

dwhite4415:06:55

same as when i do java -version

Alex Miller (Clojure team)15:06:22

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

Alex Miller (Clojure team)15:06:12

I can imagine something like that from a security pov

Alex Miller (Clojure team)15:06:22

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

dwhite4415:06:50

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

dwhite4415:06:16

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

Alex Miller (Clojure team)16:06:00

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

dwhite4416:06:13

network calls to higher ports?

ghadi16:06:42

privilege for low ports is on listening sockets, not destinations

delaguardo16:06:27

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

ghadi16:06:37

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

ghadi16:06:48

(reading through scrollback)

borkdude16:06:01

it's always the virus scanners

dwhite4416:06:37

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

borkdude16:06:49

are you on windows?

dwhite4416:06:54

but none of my co-workers are having this issue

dwhite4416:06:59

no. mac Catalina

borkdude16:06:19

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

dwhite4416:06:20

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

Alex Miller (Clojure team)16:06:12

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

dwhite4416:06:55

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?

ghadi16:06:59

can always check the diagnostic logs for rejected connection attempts

dwhite4416:06:11

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

ghadi16:06:22

(AV tools, surveillance ware or macOS Console)

ghadi16:06:40

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

Alex Miller (Clojure team)16:06:46

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

ghadi16:06:27

most solid hypothesis so far ^

Alex Miller (Clojure team)16:06:37

lein doesn't do the exec and works

borkdude16:06:51

so then clojure would work, but not clj?

Alex Miller (Clojure team)16:06:00

well they both exec at the end

borkdude16:06:03

oh wait, clojure also does exec

Alex Miller (Clojure team)16:06:38

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

borkdude16:06:40

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

borkdude16:06:59

(just to confirm the theory more)

borkdude16:06:49

@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

dwhite4416:06:58

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

borkdude16:06:05

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

dwhite4416:06:43

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

borkdude16:06:48

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 <uberjar>.jar -Spath

borkdude16:06:15

let's take it one step at a time

dwhite4416:06:43

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

dwhite4416:06:04

well maybe not confirms but more evidence

dwhite4416:06:01

yes it does work using borkdude/deps

Alex Miller (Clojure team)16:06:46

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

dwhite4416:06:01

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

dwhite4416:06:30

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!

borkdude17:06:13

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

alias exec=''

borkdude17:06:10

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)

Alex Miller (Clojure team)17:06:18

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

borkdude17:06:54

I tested it and it seems to work

borkdude17:06:08

at least in zsh

Alex Miller (Clojure team)17:06:31

that you can do that :)

borkdude17:06:48

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

borkdude17:06:58

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

borkdude17:06:58

This seems to work: clojure2:

#!/usr/bin/env bash

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

source clojure $@

borkdude17:06:30

(I don't give up)

dwhite4418:06:05

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

borkdude18:06:51

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

borkdude18:06:09

if the error persists, bisect the script

borkdude18:06:17

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

borkdude18:06:33

perhaps that will tell you something, not sure

borkdude18:06:26

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

dwhite4418:06:53

copying the original script and removing the execs does work

borkdude18:06:14

ok, well, maybe keep doing that then :)

dwhite4418:06:59

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

dwhite4419:06:09

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