12 November 2018

[FIXED] Java MacOS Hostname

During the development of Caltic, there is a strange from internal logger of Vert.x (our toolkit to build Caltic Systems). There're some warning log indicate something happen abnormally. See below:
[INFO] Nov 08, 2018 5:24:50 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Watched paths: [/Users/myrepublic/devel/caltic/caltic-train/target/classes]
[INFO] Nov 08, 2018 5:24:50 PM io.vertx.core.impl.launcher.commands.Watcher
[INFO] INFO: Starting the vert.x application in redeploy mode
[INFO] Starting vert.x application...
[INFO] 18b3e3d3-043d-4f63-b8aa-52d018554b6a-redeploy
[INFO] Nov 08, 2018 5:24:53 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 2858 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:54 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 3859 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:55 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-0,5,main] has been blocked for 4863 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:58 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 2520 ms, time limit is 2000
[INFO] Nov 08, 2018 5:24:59 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 3524 ms, time limit is 2000
[INFO] Nov 08, 2018 5:25:00 PM io.vertx.core.impl.BlockedThreadChecker
[INFO] WARNING: Thread Thread[vert.x-eventloop-thread-1,5,main] has been blocked for 4524 ms, time limit is 2000
It was happen when I upgraded MacOS Sierra to MacOS Mojave and along with it also upgraded JDK 1.8_171 to 1.8_181. For several weeks, I think it's not cause serious problem since the logs doesn't appear when the apps deployed to Heroku.
Later when I read Vert.x Core Manual, I carried to actor model and one of them that using actor model is Akka. Yeah, one year ago when I did research on Play Framework, the web framework for Java and Scala, I also found Akka, but I didn't found Akka deeper, when read one by one topic in Play. But now I understand that Play is only one implementation module (Akka Http) from many modules that Akka have, like Akka Actors, Akka Streams, etc. Back to the topic, when I tried the Lagom Framework, the new brand from Lightbend for microservice purpose, I also notified that something happen when starting Http Server. In the warning logs from Lagom, there is an url recommendation to solve this issue, here. Then the investigation is started.
After cloned git repository from the url above and run it on my machine, I got:
~$ java -jar bin/inetTester.jar
Calling the hostname resolution method...
Method called, hostname Heru-MacBook-Pro.local, elapsed time: 5011 (ms)
~$
Wow it's take a time 5 sec to getting the hostname, too long. Based on the url from Lagom logs, the proposed solution is fixed file /etc/hosts. The file should be consists of:
127.0.0.1   localhost Heru-MacBook-Pro.local
::1         localhost Heru-MacBook-Pro.local
The format above is <ip><localhost><hostname>. The hostname is grabbed from inetTester logs above, in my case is Heru-MacBook-Pro.local. Actually I'm using VIM to edit this file, but if you don't familiar with them, you could using echo.
~$ sudo echo "127.0.0.1 localhost Heru-MacBook-Pro.local" > /etc/hosts && sudo echo "::1 localhost Heru-MacBook-Pro.local" >> /etc/hosts
When password is asked, type on the terminal then enter. After you running these command, you could verify with cat command.
~$ cat /etc/host
127.0.0.1   localhost Heru-MacBook-Pro.local
::1         localhost Heru-MacBook-Pro.local
~$
Ok the proposed solution has been run, now time to verify. We can move to inetTester app again, run it:
~$ java -jar bin/inetTester.jar 
Calling the hostname resolution method...
Method called, hostname Heru-MacBook-Pro.local, elapsed time: 8 (ms)
~$
Amazing, you see it? It's only take time 8 mili-sec, so faster than before (5 sec). Now let's try the caltic app.
Vert.x Application Log
No blocked thread anymore. Since the threshold of each event loop from vertx is 2000 ms, so if your code is taken more time to be processed than the threshold, the warning log should be appeared, otherwise. Case Closed!

10 November 2018

Revamped

There are several reasons why I'm doing revamp for this blog. First, right now I'm actually a software engineer not a pentest anymore. this is why revamping this blog is a good idea. Because I can write again as usual, mostly the topic may change from security topic into developer topic. The pain is, that I need to update several point of this blog before I actually can write a post, starting from this post. But I think it's a good way for me to increase writing skill also enrich my story telling.
The second, to share everything that I got some problems and how could I fix it, it's usually what I did before this revamp. But yeah, the software development side is very broad of problems. We need to integrate between one language with the framework, library with other library, library with application server, so on and so on. And again, there are a lot of problems that can make a software engineer frustrated. Actually we find the answer by googling and stackoverflow.
At this point there are many problems that I facing everyday in software development and figure out how to fix them. Move from one problems to another, make software development is more challenging. The hard things for me, when you're using the new languages or new conceptual design, you need to understand what happen behind the screen not only in front of screen.
Last but not least, let's go to this revamped blog. Hello World!